levp / wrapper-webpack-plugin

A webpack plugin that wraps output files (chunks) with custom text or code.
91 stars 37 forks source link

Avoid minification #6

Closed DogAndHerDude closed 5 years ago

DogAndHerDude commented 5 years ago

Currently with webpack 4 if you use minification as it is intended, the wrapper output gets all minified, and that's really bad for what we're trying to do. As the platform that requires the wrapped content cannot understand minified IIFE returns.

Would there be a solution to that?

    minimizer: [
      new UglifyJSPlugin({
        parallel: true,
        uglifyOptions: {
          parse: {
            bare_returns: true,
          },

          compress: {
            warnings: false,
            dead_code: true,
            drop_console: false,
          },

          output: {
            comments: false,
          },

          mangle: true,
        },
      }),
    ],
levp commented 5 years ago

Originally it was made like this by design and it still is, but I see the need for what you're asking for.

I've done a bit of testing and this can easily be accomplished by using webpack's afterOptimizeChunkAssets event hook instead of optimizeChunkAssets.

I'll publish a new version with this option ASAP.

levp commented 5 years ago

@TheImpressionist

Version 2.1.0 has just been published to npm, it features an afterOptimizations option that when set to true should do exactly what you asked for.

Hope that solves your issue.