prateekbh / babel-esm-plugin

Add this plugin to generate mirrored esm modules for your existing bundles
MIT License
192 stars 16 forks source link

Automatically switch Terser/Uglify to ecma:8 input & output #35

Closed developit closed 4 years ago

developit commented 5 years ago

The child compiler spawned by babel-preset-modules needs to change Terser's parsing and output modes to ecma:8 in order to preserve arrow functions and other constructs, and to allow it to minify modern syntax effectively.

developit commented 4 years ago

@prateekbh I have an implementation now that I will PR ASAP.

prateekbh commented 4 years ago

Thanks i'll publish it ASAP after merging

fengzilong commented 4 years ago

I would like to send a PR for this issue, but I was stuck with a question

If I use terser-webpack-plugin in this way

webpack.config.js

{
  optimization: {
    minimizer: [
      {
        apply( compiler ) {
          const TerserPlugin = require( 'terser-webpack-plugin' )
          new TerserPlugin( {
            terserOptions: { output: { ecma: 5 } }
          } ).apply( compiler )
        }
      }
    ]
  }
}

Like what webpack defaults.js did

I can't access terser instance with parentCompiler.options.optimization.minimizer anymore

Any advice for how to access and modify the terserOptions in this case please @prateekbh @developit

prateekbh commented 4 years ago

Sadly we lately realized that doing this wouldn't really make much of a difference in the output.

Not really worth putting much efforts in