require

用tsc编译ts

落爺英雄遲暮 提交于 2019-12-02 18:53:09
源代码 /*因为编译后的代码包含es6新增api,比如下边的includes,有浏览器可能不支持,故而需要引入垫片 这里可以选择core-js,也可以ts-polyfill,目的都是一样的*/ import 'core-js'; //具体目标 class Utils { protected cname:string = 'Utils'; public test(): void{ [1,2,3].includes(2) } } (window as any).subject = new Utils(); //方便页面使用 使用tsc编译 tsconfig.json配置如下 { "compilerOptions": { "target": "es5", /* 编译的目标是什么版本的 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "module": "commonjs",/* 编译后模块化类型 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ "lib": [ //编译过程中需要引入的库文件的列表。 "es5", "es2016.array.include", "dom

最详细的vue脚手架vue-cli2、vue-cli3讲解

五迷三道 提交于 2019-12-02 17:50:51
前言: vue脚手架指的是vue-cli它是vue官方提供的一个快速构建单页面(SPA)环境配置的工具,cli 就是(command-line-interface ) 命令行界面 。vue-cli是基于node环境利用webpack对文件进行编译、打包、压缩、es6转es5等一系列操作。目前vue-cli已经升级到了3.0版本,3.0所需的webpack版本是4.xxx,2.0版本目前也很流行,2.0所需的webpack版本是3.xxx,我们来讲讲两者的配置: Vue2.0:     一.安装node.js环境:     去node官网下载node.js并安装(http://nodejs.cn/download/)。安装完成后可以在终端执行 node -v查看node 是否安装成功,下图是安装成功的提示,显示出当前安装的node的版本号。         二.全局安装webpack:     为了在其他任何目录下都能使用到webpack,进行全局安装,执行npm install webpack@3.12.0 -g 命令,npm 是Node集成的工具 npm install 是从github上下载webpack最新的包,“@3.12.0”表示安装指定的版本,因为现在已经升级到了4.0版本,如果不指定版本版本号就会安装最新的版本,同时vue-cli2需要的是3.xxx的版本

How to Use one module feature within another module in nodejs require()

旧时模样 提交于 2019-12-02 17:43:28
问题 I want to use one module feature within another module file main.js var _ = require("./underscore.js"); var foo = require("./bar.js"); foo.publish(...); file bar.js (function(e) { var array = [...]; e.publish = function(t, args) { _.each(array, function(...) {...}); }); })(exports); I've tried a couple of variations, but I am not sure of the best way around this error: ReferenceError: _ is not defined 回答1: Yes, you should use in every module which needs that variable, for the case of you

Neither ruby and nor irb can load .rb file in current directory

不羁岁月 提交于 2019-12-02 17:30:49
I'm having a really noob problem with importing files in Ruby. I'm making a Ruby app in Windows XP. All the class files for the app are in "C:/Documents/Prgm/Surveyor_Ruby/lib" . But when I require a file in another file, neither ruby nor irb can find the required file. The current directory's contents: C:\Documents\Prgm\Surveyor_Ruby\lib>dir Volume in drive C has no label. Volume Serial Number is AAAA-BBBB Directory of C:\Documents\Prgm\Surveyor_Ruby\lib 10/09/2010 06:32 PM <DIR> . 10/09/2010 06:32 PM <DIR> .. 10/08/2010 03:22 PM 5,462 main (commented).rb 10/08/2010 03:41 PM 92 question.rb 10

Since I change the tree, absolute and relative path don't work

烂漫一生 提交于 2019-12-02 16:18:35
问题 I tried to use the absolute path to include my files : I have 4 files (I have other file on my localhost but oddly the inclusion works well) : header.php ( C:\wamp\www\MySite\layout\header.php ) <?php session_start (); require_once '/pdo.php'; .... pdo.php ( C:\wamp\www\MySite\pdo.php ) <?php require_once '/class/User.php'; require_once '/class/Order.php'; .... forms/login.php ( C:\wamp\www\MySite\forms\login.php ) <?php session_start (); include '/pdo.php'; .... login.php ( C:\wamp\www

webpack使用CMD、AMD、CommonJS、ES6区别以及运用

巧了我就是萌 提交于 2019-12-02 15:29:52
之前在网上浏览器的webpack模块化很乱,而且也没有把CMD模块化使用讲清楚的,终于忍不下去,将几种模块化以一种清晰的方式写出来,这也是我一直想做的事,下面就来讲讲CMD、AMD、commonJs、es6模块化的运用。 CMD CMD是seaJs在推广过程中生产的对模块定义的规范 属于同步模块定义,在哪里需要用就在哪里引入, 用define定义 定义方法: define(function(){require,exports, module}) require: 导入其他依赖的办法 exports、导出的方法 导出的方法 CMD有三种方式导出 第一种使用exports导出 //common.js //使用define定义模块,require、exports、module是define自带的 define ( function ( require , exports , module ) { //定义导出的方法 function minus ( a , b ) { return a - b } // 使用exports导出 exports . minus = minus } ) 第二种使用moudle导出 //common.js //使用define定义模块,require、exports、module是define自带的 define ( function ( require ,

nodejs学习笔记

左心房为你撑大大i 提交于 2019-12-02 15:17:29
nodejs创建服务器 http.createServer(),response.writeHead(),response.end() var http = require ( 'http' ); http . createServer ( function ( request , response ) { // 发送 HTTP 头部 // HTTP 状态值 : 200 : OK // 内容类型 : text/plain response . writeHead ( 200 , { 'Content-Type' : 'text/plain' }); // 发送响应数据 "Hello World" response . end ( 'Hello World\n' ); }). listen ( 8888 ); // 终端打印如下信息 console . log ( 'Server running at http://127.0.0.1:8888/' ); nodejs回调函数 回调函数在完成任务后就会被调用,Node 使用了大量的回调函数,Node 所有 API 都支持回调函数。 我们可以一边读取文件,一边执行其他命令,在文件读取完成后,我们将文件内容作为回调函数的参数返回。这样在执行代码时就没有阻塞或等待文件 I/O 操作。这就大大提高了 Node.js 的性能

Webpack4建造Vue项目

旧巷老猫 提交于 2019-12-02 15:14:18
前言 本篇文章除前言以及后记部分之外均为转载,转载文章发布于 2018-08-22 ,所以关于依赖和插件的配置 方法部分有些过时,所以正文内容仅供参考,大家多多查看对应插件的官方文档。 我会在后记部分贴出自己配置的vue项目作为参考。 项目建设 项目初始化 创建createVue文件夹,进入该文件夹, npm init 初始化项目 安装webpack四件套 npm i webpack webpack-cli webpack-dev-server webpack-merge --save-dev // 当前我使用版本 "webpack": "^4.16.3", "webpack-cli": "^3.1.0", "webpack-dev-server": "^3.1.5", // 开发服务器 "webpack-merge": "^4.1.4" // webpack 配置合并 复制代码 创建相应文件 createVue |--dist |--build |--webpack.prod.js |--webpack.dev.js |--webpack.base.js |--src |--index.js |--app.vue |--index.html 复制代码 // webpack.base.js // 存放 dev 和 prod 通用配置 const webpack = require(

Webpack 4.X 从入门到精通 - module(四)

本小妞迷上赌 提交于 2019-12-02 14:01:05
概念 在 webpack 中任何一个东西都称为模块, js 就不用说了。一个 css 文件,一张图片、一个 less 文件都是一个模块,都能用导入模块的语法( commonjs 的 require , ES6 的 import )导入进来。 webpack 自身只能读懂 js 类型的文件,其它的都不认识。但是 webpack 却能编译打包其它类型的文件,像 ES6 、 JSX 、 less 、 typeScript 等,甚至 css 、 images 也是Ok的,而想要编译打包这些文件就需要借助 loader loader 就像是一个翻译员,浏览器不是不认识这些东西么?那好交给 loader 来办,它能把这些东西都翻译成浏览器认识的语言。 loader 描述了 webpack 如何处理非 js 模块,而这些模块想要打包 loader 必不可少,所以它在 webpack 里显得异常重要。 loader 跟插件一样都是模块,想要用它需要先安装它,使用的时候把它放在 module.rules 参数里, rules 翻译过来的意思就是规则,所以也可以认为 loader 就是一个用来处理不同文件的规则 文件目录 这节课需要用到图片跟样式,所以我要按传统的目录结构来创建目录,目录如下 结构目录 处理CSS 所需loader style-loader //把处理完的css放到style标签里

Ruby Strange Error

有些话、适合烂在心里 提交于 2019-12-02 11:39:07
Whenever I require a file in ruby or irb I get this error: LoadError: no such file to load -- (insert any filename).rb from <internal:lib/rubygems/custom_require>:29:in `require' from <internal:lib/rubygems/custom_require>:29:in `require' from (irb):1 from /usr/bin/irb1.9.1:12:in `<main>' It happens even if the file exists I am using ruby1.9.1 and to my knowledge, I have not installed rubygems. I am running on Ubuntu 10.10 Maverick Meerkat. Please help, this problem is very annoying! Thanks in advance, ell. EDIT: I forgot to say that no matter where the file is, even if its in the same