Serverless-webpack: How to disable minification?

Created on 11 Mar 2018  路  4Comments  路  Source: serverless-heaven/serverless-webpack

I don't have uglifyJS in my webpack config, but for some reason the output does seem minified:

screen shot 2018-03-11 at 13 36 00

I don't really need minification, and would like to disable it. Does anyone have an idea where minification is enabled in the first place?

question

Most helpful comment

Hi @tommedema , do you use Webpack 4?

They have changed the semantics there. If you set mode: "production" in your webpack config with Webpack 4, minification is enabled by default (together with other more useful optimization algorithms 馃槃 )

If you use Webpack 4 + serverless-webpack 5.0.0, you should set the follwing in your webpack config:

    mode: slsw.lib.webpack.isLocal ? "development": "production",
    optimization: {
        // We no not want to minimize our code.
        minimize: false
    },

Then you end up with optimized, but not minified code. The conditional mode switch enables all debugging extensions automatically when running locally with invoke local or serverless-offline but gives you better code when deployed.

All 4 comments

Hi @tommedema , do you use Webpack 4?

They have changed the semantics there. If you set mode: "production" in your webpack config with Webpack 4, minification is enabled by default (together with other more useful optimization algorithms 馃槃 )

If you use Webpack 4 + serverless-webpack 5.0.0, you should set the follwing in your webpack config:

    mode: slsw.lib.webpack.isLocal ? "development": "production",
    optimization: {
        // We no not want to minimize our code.
        minimize: false
    },

Then you end up with optimized, but not minified code. The conditional mode switch enables all debugging extensions automatically when running locally with invoke local or serverless-offline but gives you better code when deployed.

BTW: The new configuration options are not documented really well in the Webpack documentation (and hard to find at all), but I found a quite good explanation here: https://medium.com/webpack/webpack-4-mode-and-optimization-5423a6bc597a that helped us to understand how we should configure our projects now.

This is excellent, thanks a ton!

where to find the webpack config

Was this page helpful?
0 / 5 - 0 ratings