使用Grunt-babelify-browserify而不导入节点模块
我正在用webdriver.io编写自动化testing。 我正在使用grunt / babelify / browserify,以便我可以在ES6中编写testing。 我在脚本中需要一些节点模块。 我希望能够不将这些节点文件编译到我的分发脚本中,而是直接打印出require语句,因为我仍在运行脚本服务器端。 换句话说,是否有一种方法可以通过browserify“按原样”来代码? 这里是我要求的模块:
required libraries var webdriverio = require('webdriverio'); var chai = require("chai"); chai.config.includeStack = true; // prints out full call stack var expect = chai.expect; var chaiAsPromised = require("chai-as-promised"); chai.use(chaiAsPromised);
这是我的咕噜文件:
module.exports = function (grunt) { grunt.initConfig({ browserify: { dist: { options: { transform: [ ["babelify", { loose: "all" }] ] }, files: { // if the source file has an extension of es6 then // we change the name of the source file accordingly. // The result file's extension is always .js "./dist/module.js": ["./modules/*"] } } }, watch: { scripts: { files: ["./modules/*/*.js"], tasks: ["browserify"] } } }); grunt.loadNpmTasks("grunt-browserify"); grunt.loadNpmTasks("grunt-contrib-watch"); grunt.registerTask("watch", ["watch"]); grunt.registerTask("build", ["browserify"]); };
那么,如果你只是想ES6到ES5的function,而不把文件合并成一个包,最直接的方法就是简单地使用Babel而不是Babelify和Browserify。
Babel是Browserify的Babelify变换的工具。
不过,我应该注意到,node6的许多function都已经被node.js支持 ,所以你可以在没有Babel或者Browserify的情况下运行脚本进行本地testing。
- 使用Browserify和jQuery插件
- pipe道subprocessstdout&标准input到浏览器在node.js&browserify
- 当通过Browserify加载时,Mongoose没有连接方法
- Karmatesting在手表模式下通过,但在单一标志通过时失败
- 如何使用browserify“删除”/“更改”一些需要(…)调用?
- browserify&factor-bundle依赖关系ID
- 我可以在浏览器/ node.js上使用不同的库,而无需编辑package.json?
- 如何以特定顺序运行Gulp任务
- Amazon S3提供InvalidDigest:您指定的Content-MD5无效