import NavBar from "nav-bar.babel";var Panels = require("panels.babel");
NOTE: By default, Browserify will only lookup .js and .json files when the extension is ommited (like node's require). To lookup additional extensions, use browserify's extensions option.
Now you can omit the extension and compile .babel files:
import NavBar from "nav-bar";var Panels = require("panels");
Source maps
By default, browserify sets the source map sources paths relative to the basedir (or to process.cwd() if not set). To make the sources paths absolute, set the sourceMapsAbsolute option on babelify:
browserify().transform(babelify.configure({ // Optional ignore regex - if any filenames **do** match this regex then // they aren't compiled ignore: /regex/, // Optional only regex - if any filenames **don't** match this regex // then they aren't compiled only: /my_es6_folder/}))
Babelify emits a babelify event with Babel's full result object as the first
argument, and the filename as the second. Browserify doesn't pass-through the
events emitted by a transform, so it's necessary to get a reference to the
transform instance before you can attach a listener for the event:
var b = browserify().transform(babelify);b.on("transform", function(tr) { if (tr instanceof babelify) { tr.once("babelify", function(result, filename) { result; // => { code, map, ast, metadata } }); }});
FAQ
Why aren't files in node_modules being transformed?
This is the default browserify behavior.
A possible solution is to add:
{ "browserify": { "transform": ["babelify"] }}
to the root of all your modules package.json that you want to be transformed. If you'd like to
specify options then you can use:
Another solution (proceed with caution!) is to run babelify as a global transform. Use the babel ignore option to narrow the number of files transformed:
The above example will result in a transform that also includes the app module in node_modules: the global flag transform all files, and the ignore regular expression then excludes all those in the node_modules directory except those that are in node_modules/app (since ?! will match if the given suffix is absent).
Why am I not getting source maps?
To use source maps, enable them in browserify with the debug option:
browserify({debug: true}).transform("babelify");
$ browserify -d -t [ babelify ]
If you want the source maps to be of the post-transpiled code, then leave debug on, but turn off babelify's sourceMaps: