Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

How to minify the css file extract by extract-text-webpack-plugin? #434

Closed
qidaneix opened this issue Feb 26, 2017 · 6 comments
Closed

How to minify the css file extract by extract-text-webpack-plugin? #434

qidaneix opened this issue Feb 26, 2017 · 6 comments

Comments

@qidaneix
Copy link

I use webpack@2.2.1 and extract-text-webpack-plugin to extract css into a separate .css file. I have read the document but I can find a way to minify the .css file. How to do it?

@michael-ciniawsky
Copy link
Member

@qidaneix Set the minimize option in css-loader

+ { loader: 'css-loader', options: { minimize: true } )

or use postcss-loader+ cssnano, csso-loader etc. ExtractTextPlugin has nothing to do with minification, it's just for extraction regardless if contents are minified or not. 😛

@albertogasparin
Copy link

@qidaneix @michael-ciniawsky
The downside of css-loader is that the minification is per included file, not global. If you like to have the entire css bundle minified I would suggest you to have a look at OptimizeCssAssetsPlugin.

@qidaneix qidaneix closed this as completed Mar 5, 2017
@armandoborge
Copy link

Despite this issue is closed, maybe this code can help other developers looking for the same:


module: {
            rules: [
                {
                    test: /\.css$/,
                    use: ExtractTextPlugin.extract({
                        fallback: 'style-loader',
                        use: [
                            { loader: 'css-loader', options: { minimize: true } }
                        ]
                    })
                }
           ]
}

@chhaymenghong
Copy link

chhaymenghong commented Feb 6, 2018

@albertogasparin I tried using OptimizeCssAssetsPlugin, but it seems to embed the sourcemap information inside the css bundle itself and as a result increase the bundle size. Any ideas on how to make the sourceMapUrl to point to a map file instead?

@albertogasparin
Copy link

@chhaymenghong I'm actually turning css source maps off on production. You already reported it, so let's see what the owner has to say

@X-Y
Copy link

X-Y commented Oct 23, 2018

For anybody using css-loader 1.0.0, the minimize options is removed and you have to use postcss + cssnano instead.
https://github.com/webpack-contrib/css-loader/blob/master/CHANGELOG.md

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants