babel / minify

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

Class names not mangled #562

Closed gauntface closed 7 years ago

gauntface commented 7 years ago

I'm using Babili with Rollup and at the moment babili is removing comments and its mangling variable names, but class names are remaining untouched, not sure why. Everything I can see / have tried, this should either work out the box.

const babel = require('rollup-plugin-babel');

// This is passed into rollup plugins
const babelPlugin = babel({
  presets: [['babili', {
    comments: false,
  }]],
});

The resulting code is in an iife, so I don't think there is any issue with global scope and renaming. Does anyone have any ideas / tips?

goto-bus-stop commented 7 years ago

Do you have some example code or perhaps a small project to reproduce?

Note that rollup-plugin-babel runs on each individual module before the code is bundled, so even if rollup adds an iife around the output, it won't yet be there when babili runs.

gauntface commented 7 years ago

I don't have a small example, but this is a result of workbox: https://github.com/GoogleChrome/workbox/

It's likely that Rollup is our issue by the sound of it. Would it be insane to use Rollup for bundling and module format and then use babel to minify in a seperate step?

goto-bus-stop commented 7 years ago

Would it be insane to use Rollup for bundling and module format and then use babel to minify in a seperate step?

Not at all!

boopathi commented 7 years ago

Short answer:

Long answer:

gauntface commented 7 years ago

Thanks for the extra info @boopathi. I did try running with an option that looked like it would mangle top level classes and functions, but that didn't seem to take affect but by the sounds of it, if it works, it would be preferable in rollup-plugin-babel (i.e. using transform)

boopathi commented 7 years ago

Are you facing any issues with

{
  presets: [
    [
      "babili",
      {
        mangle: { topLevel: true }
      }
    ]
  ]
}