使用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。