1

我正在用 webdriver.io 编写自动化测试。我正在使用 grunt/babelify/browserify 以便我可以在 ES6 中编写测试。我的脚本中需要一些节点模块。我希望能够不将这些节点文件编译到我的分发脚本中,而只是按原样打印出 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"]);
};
4

1 回答 1

1

好吧,如果你只想要 ES6 到 ES5 的功能而不将文件组合成一个包,最直接的方法是简单地单独使用Babel而不是 Babelify 和 Browserify。

Babel 是 Browserify 的 Babelify 转换背后的工具。

然而,我应该注意到,ES6 的许多特性已经被 node.js 支持,所以你也许可以在没有 Babel 或 Browserify 的情况下运行你的脚本来进行本地测试。

于 2016-03-24T17:05:58.083 回答