Webpack critical css extraction plugin
Is used for "semi-automatic" extraction of critical parts from css bundles.
Can work along with webpack-rtl-plugin.
Installation
$ npm install webpack-extract-critical-css-plugin
Usage
Add the plugin to your webpack configuration:
const WebpackRTLPlugin = ;const ExtractCriticalCSSPlugin = ; moduleexports = entry: path output: path: path filename: 'bundle.js' module: loaders: test: /\.css$/ loader: ExtractTextPlugin plugins: minimize: browsers: '> 1%' 'last 2 versions' 'Firefox >= 20' preset: 'default' customMedia: 'feed-widget-idea-critical': 'feed-widget-idea-critical' minify: !isDev rtlPluginSupport: true rtlOptions: // should be surrounded by dots. E.g. `filename.rtl.css` fileNameTag: 'rtl'
In your css-module wrap the rule with custom @media, e.g. @media feed-widget-idea-critical {} all rules under this mq will be processed to separate css-file. Custom rule will be cut from original chunk
This will create feed-widget-idea-critical.css
, containing critical css rules.
Options
new ExtractCriticalCSSPlugin({
minimize: {
browsers: ['> 1%', 'last 2 versions', 'Firefox >= 20'],
preset: 'default',
},
customMedia: {
'feed-widget-idea-critical': 'feed-widget-idea-critical'
},
minify: !isDev,
rtlPluginSupport: true,
rtlOptions: {
// should be surrounded by dots. E.g. `filename.rtl.css`
fileNameTag: 'rtl'
}
})
minimize
[Array] options will be passed tocssnano
minimizer.customMedia
[Array], holding map for custom @media-queries to filename, that will be produced for the rules under this query.minify
[boolean] will minify the resultrtlPluginSupport
[boolean] will separately parse rtl-versions of chunksrtlOptions
[Array] of options fot rtl supportfileNameTag
[string] 'rtl', by default. an additional part of rtl-version of chunk. E.g. filename.rtl.css