babel/babelify: Browserify transform for Babel

Why aren’t files in node_modules being transformed with Browserify?

https://github.com/babel/babelify#why-arent-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:

smartplug/package.json

{
  "name": "smartplug",
  "version": "2.1.0",

  "browserify": {
    "transform": [
      ["babelify", { "presets": ["env"] }]
    ]
  }
}

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:

browserify().transform("babelify", {
  global: true,
  ignore: /\/node_modules\/(?!app\/)/
});

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

Leave a Reply