leftstick / unminified-webpack-plugin

Generator un-minified JavaScript files along with minimize.
MIT License
60 stars 7 forks source link

Webpack 4 example? #23

Closed dotnetshadow closed 3 years ago

dotnetshadow commented 6 years ago

Hi there,

Great library. I'm trying to get this to work with webpack 4. I used to be able to get it to work with webpack 3, but since upgrading the css stays minified

optimization: {
            minimizer: [
                // we specify a custom UglifyJsPlugin here to get source maps in production
                new UglifyJsPlugin({
                    cache: true,
                    exclude: [/\.min\.js$/gi],
                    parallel: true,
                    uglifyOptions: {
                        compress: false,
                        ecma: 6,
                        mangle: true,
                        output: {
                            comments: false
                        },
                        warnings: false
                    },
                    sourceMap: true
                }),

                new OptimizeCssAssetsPlugin({                    
                    cssProcessorOptions: { discardComments: { removeAll: true }, safe: true }
                })                
            ]
        },
        plugins: [

            new CleanWebpackPlugin(
                ['./wwwroot/js', './wwwroot/css'], {
                    verbose: true,
                    dry: false,
                    exclude: ['shared.js']
                }),

            new UnminifiedWebpackPlugin(),

            ....
leftstick commented 6 years ago

Hi, i gave a quick look at optimize-css-assets-webpack-plugin, seems it is designed to be called at the last step of webpack lifecycle before generating assets. Which means, the unminified css created via unminified-webpack-plugin will be minified in optimize-css-assets-webpack-plugin at the last step.

I will take more time to investigate it, thanks for pointing out this issue

dotnetshadow commented 5 years ago

Hi there, any update on this?

UPDATE I updated OptimizeCssAssetsPlugin and used clean-css and I think the unminified is working

new OptimizeCssAssetsPlugin({
                    assetNameRegExp: /\.min\.css$/g,
                    cssProcessor: CleanCss,
                    cssProcessorOptions: { discardComments: { removeAll: true }, safe: true }
                })