babel / babelify

Browserify transform for Babel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not working "Why aren't files in node_modules being transformed?"

mmmDanone opened this issue · comments

Not working:
.transform(babelify, { global: true, ignore: [/\/node_modules\/(?!app\/)/] })

This works for me: ignore: [/^(?!.*\/node_modules\/app\/)/]

I can confirm that babelify does not globally transform node_modules if you specify { global: true }.

@niftylettuce I am seeing this too. I'm not able to transform any of the required node_modules. even when I set {global: true, ignore: undefined }

@builtbylane I have a pretty cool solution/alternative that even has factor-bundle built-in. Will share soon. IMO there is a core bug somewhere here that nobody has figured out or dedicated time to. Obviously this is broken. The better solution is to run browserify and then babel separately.

@niftylettuce I was just starting to go down that same path but got sidetracked. Please share! 🥗

I just have to push it up, need a little bit longer

Assuming you're using Babel 7:
It is hard to say since this didn't specify how it is configuring things, but everything in https://babeljs.io/docs/en/config-files applies here. If you're using a .babelrc file, it is still package-scoped, even if you run the transform itself with global: true, so make sure you're using a babel.config.js,

OK it's done. v0.2.9 of Lad has an updated gulp config that satisfies our needs here.

npm install -g lad

https://lad.js.org

https://github.com/ladjs/lad/blob/master/template/gulpfile.js#L181-L199

Happy hacking, and feel free to join our Slack @ https://slack.crocodilejs.com/

@loganfsmyth I've changed my config file to babel.config.js to no avail. Babelify still doesn't honor my settings for the node_modules

I can't seem to get this to work at all. The global option no longer works, setting ignores in my gulpfile does not work, removing my config into babel.config.js or babel.config.json does not work. I'm stumped as to how I can transfom a package. Any help would be greatly appreciated.

any news about this ?.......

Does anybody know how the ignore pattern can be used inside npm scripts on the command line?

I have this in my npm scripts:

"js": "browserify script.js --outfile bundle.js -t [ babelify --global --ignore [ node_modules\/(?!swiper) ] ]",

Result:
Syntax error: "(" unexpected

"js": "browserify script.js --outfile bundle.js -t [ babelify --global --ignore [ node_modules\/\\(?!swiper\\) ] ]",

Result:
Doesn't work, since it does not properly ignore all packages except the defined ones.

Just found a clever way:

"js": "browserify script.js --outfile bundle.js -t [ babelify --global --only [ _js node_modules\/swiper ] ]",

You can define more packages to transform by adding them (space separated) to the array of only.

Gentlemen, I believe we all have been deceived by Windows once again.
I've added some logging and noticed that we have \ instead of / in filename:

babelOpts: {
    ignore: [ /node_modules\/(?!whatwg-fetch)/ ],
    presets: [ [Array] ],
    assumptions: { arrayLikeIsIterable: true },
    sourceType: 'module',
    cwd: 'C:\\Users\\maxim\\browserify-temp',
    caller: { name: 'babelify' },
    filename: 'C:\\Users\\maxim\\browserify-temp\\node_modules\\core-js\\internals\\to-object.js',
    sourceFileName: undefined
  }

So the fix is to make it platform-independent:

ignore: [/[/\\]node_modules[/\\](?!whatwg-fetch[/\\])/],

Hope it helps!