1

I'm writing automated tests with webdriver.io. I'm using grunt/babelify/browserify so that I can write the tests in ES6. I have required some node modules in my script. I want to be able to NOT compile those node files into my distribution script, but simply print out the require statements as is since i'm still running the script server side. In other words, is there a way to carry over code "as is" with browserify? Here are the modules I'm requiring:

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);

Here is my grunt file:

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"]);
};
mags
  • 590
  • 1
  • 8
  • 25

1 Answers1

1

Well, if you just want the ES6-to-ES5 capabilities without combining the files into a bundle, the most straightforward way is to simply use Babel on its own rather than Babelify and Browserify.

Babel is the tool behind the Babelify transform for Browserify.

I should note, however, that many features of ES6 are already supported by node.js, so you might just be able to run your script without Babel or Browserify for local testing.

harperj
  • 63
  • 5
  • I do actually want to combine files but NOT the node modules. Is there a way to tell browserify to ignore the node require statements but not the es6 import/export statements? – mags Mar 24 '16 at 18:32
  • ok, i decided what I was trying to do was a bit silly since node does support most es6 features. I'm just going to skip the grunt tasks for now. Thanks! – mags Mar 24 '16 at 19:21
  • 1
    @mags No problem! But as an idea if you'd still like to combine all of the files you might `cat` them together, and then use `grep` to remove the require lines. – harperj Mar 24 '16 at 19:36