Search code examples
reactjsgulpbrowserifybabeljs

Work flow about babel + browserify


All:

When I followed the tutorial of Facebook React, it only talked about how to transpile with Babel, but no content with browserify, I wonder if I use gulp, how to build the work flow with babel and browserify.

For example:

  1. Transpile all *.js files in /js folder, and copy them to /build/js
  2. When 1 is ready, broserify all /build/js/*.js into bundle.js and copy to /dist/js
  3. Copy *.html to /dist/

That is it! Thanks


Solution

  • You could do that, or compile and browserify in the same step with the babelify transform for browserify.

    Here is a basic example of how to compile and bundle modules in one step using babelify, and assuming an entry file that has a dependency graph that includes all of the modules you want to bundle.

    browserify('./js/entry')
      .transform(babelify)
      .bundle()
      .pipe(fs.createWriteStream('./dist/bundle.js'));