question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Determine mechanism to add plugins after `babel-preset-env` plugins.

See original GitHub issue

Currently, all user supplied plugins (in options.babel.plugins) are added before the babel-preset-env plugins (see final plugin construction code here). I believe that this is the correct default position for all plugins (as most want to operate on the raw source AST).

However, there are some circumstances where you want to write plugins that operate on the AST after the various babel transforms have occurred. The prime example of this is the babel6-plugin-strip-class-callcheck plugin, which removes the _classCallCheck for production code (which is used by ember-data).

I can think of a couple of possible solutions here, we just need to decide what to implement.

  • Option A: this emulates babel@5’s setup (which would have { transformer: ***, position: 'after' }).
this.options.babel.plugins.push({
  plugin: require('babel6-plugin-strip-class-callcheck'),
  postion: 'after'
});
  • Option B
this.options.babel.pluginsAfterTransformation = [
  require('babel6-plugin-strip-class-callcheck')
];

I’m sure there are additional options, and I’m happy for suggestions.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rwjbluecommented, Mar 15, 2017

what would be the resulting order then?

  • plugins
  • AMD modules plugin
  • preset-env
  • pluginsAfterTransformation (or better name)
0reactions
rwjbluecommented, Mar 15, 2017

Modules are processed before the rest of preset env at the moment (I’m open to changing that if y’all disagree). So I don’t really think we are offering any options other than before or after preset env.

I looked into using a DAG last night, and it would be easy enough to implement but there isn’t a defining property we could use for the before/after (e.g. Babel plugins don’t have a name property). Which means it would be very difficult…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plugins - Babel.js
If the plugin is on npm, you can pass in the name of the plugin and Babel will check that it's installed in...
Read more >
babel/preset-env
@babel/preset-env takes any target environments you've specified and checks them against its mappings to compile a list of plugins and passes it to...
Read more >
Presets - Babel.js
Babel presets can act as sharable set of Babel plugins and/or config options . Official Presets. We've assembled a few presets for common...
Read more >
Configure Babel
const presets = [ ... ]; const plugins = [ ... ]; if (process.env["ENV"] === "prod") { plugins.push(...); } module. · babel --plugins...
Read more >
Babel 7 fails with single plugin saying "Duplicate plugin/preset ...
This is a babel error basically saying that you have defined your plugin @babel/plugin-transform-regenerator twice - more or less indirectly ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found