Injecting css chunks extracted using extract-css-chunks-webpack-plugin to HTML for html-webpack-plugin Edit
npm install css-chunks-html-webpack-pluginPlugin for injecting css chunks, extracted using extract-css-chunks-webpack-plugin, to HTML for html-webpack-plugin
Use in conjunction with
extract-css-chunks-webpack-plugin and
babel-plugin-dual-import
to inject CSS chunks paths into your HTML file with
html-webpack-plugin.
The current version is incompatible with Webpack 3 or older. In order to use this plugin with Webpack 3, usecss-chunks-html-webpack-plugin@0.1.0
``bash`
npm install --save-dev css-chunks-html-webpack-plugin@0.1.0
`bash`
npm install --save-dev css-chunks-html-webpack-plugin \
mini-css-extract-plugin babel-plugin-dual-import \
html-webpack-plugin
_webpack.config.js_
`js
const ExtractCssPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CssChunksHtmlPlugin = require('css-chunks-html-webpack-plugin');
module.exports = {
// your other options
plugins: [new ExtractCssPlugin(), new CssChunksHtmlPlugin({ inject: 'head' }), new HtmlWebpackPlugin()],
};
`
You can pass an object of configuration options to CssChunkHashPlugin. Allowed values are as follows:
* inject: 'head' | 'body' | false whether to inject chunks paths script into HTML, used for manually addingtrue
chunks paths using custom template for HtmlWebpackPlugin (default )
The CSS chunks paths map is saved in htmlWebpackPlugin.files.cssHash in your template. So if you want to manually add
CSS chunks map you can do (if you are using EJS):
`ejs`
By default, it will inject script tag into
. If you want to inject the script tag with window.__CSS_CHUNKS__
into set inject: 'body'`,There is a basic example of usage in examples
You're free to contribute to this project by submitting issues and/or pull requests.
This project is licensed under MIT.