簡體   English   中英

在不導入節點模塊的情況下使用 Grunt-babelify-browserify

[英]Using Grunt-babelify-browserify without importing node modules

我正在使用 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);

這是我的 grunt 文件:

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 的功能而不將文件組合成一個包,最直接的方法是簡單地單獨使用Babel ,而不是 Babelify 和 Browserify。

Babel 是用於 Browserify 的 Babelify 轉換背后的工具。

但是,我應該注意, node.js 已經支持ES6 的許多功能,因此您可能只需要在沒有 Babel 或 Browserify 的情況下運行腳本進行本地測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM