roman01la / webpack-closure-compiler

[DEPRECATED] Google Closure Compiler plugin for Webpack
MIT License
464 stars 25 forks source link

Is there a way ignore a specific file when using webpack-closure-compiler? #23

Closed gajus closed 7 years ago

gajus commented 7 years ago

Our webpack bundle imports external scripts that we do not have control over. Is there a way to tell webpack-closure-compiler not to minify certain files, or does webpack-closure-compiler operate on the resulting bundle level?

roman01la commented 7 years ago

@gajus Yes, it optimizes the whole bundle, after Webpack puts everything together.

phyllisstein commented 7 years ago

Just wanted to point out, in case anyone else stumbles to this issue many moons later, that because the plugin passes its options hash to Webpack's ModuleFilenameHelpers, one can in fact exclude files and patterns from optimization:

new ClosureCompilerPlugin({
  compiler: {
    charset: 'UTF-8',
    compilation_level: 'SIMPLE',
    formatting: 'SINGLE_QUOTES',
    language_in: 'ECMASCRIPT5',
    language_out: 'ECMASCRIPT5',
    warning_level: 'QUIET'
  },
  concurrency: 3,
  exclude: [
    /bluebird/
  ]
})

The only caveat is that the match is made against the final built chunk name, not the name of the input module, so it's sometimes necessary to do a little dance to segment off the code you want to protect.