babel / minify

:scissors: An ES6+ aware minifier based on the Babel toolchain (beta)
https://babeljs.io/repl
MIT License
4.4k stars 225 forks source link

Support decorators with Babel7 #939

Open vaughnkoch opened 5 years ago

vaughnkoch commented 5 years ago

Hi, babel-minify is sweet, although it doesn't appear to have support for decorators like MobX's @observable. It would be great to have this support when you release Babel7 support.

It appears that MinifyPlugin (which uses babel-minify under the hood) breaks when decorators are enabled, even though Babel supports them without minification (and no browser errors).

In the example below, the code compiles with MinifyPlugin but causes a browser error on load: SyntaxError: Identifier 't' has already been declared.

The only fixes that work are mangle:false, which bloats the JS, or removing decorators entirely. I tried using @babel/core@7.2.2 and babel-minify@0.6.0-alpha.5 (and 0.5.0), but nothing seems to work.

I used this .babelrc:

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
            "esmodules": true
        },
      },
    ],
    "@babel/preset-react",
  ],

  "plugins": [
    ["@babel/plugin-proposal-decorators", { "legacy": true}],
    ["@babel/plugin-proposal-class-properties", { "loose": true}]
  ]
}

and this webpack:

const MinifyPlugin = require('babel-minify-webpack-plugin')

...

    new MinifyPlugin(),