Socket
Socket
Sign inDemoInstall

css-chunks-html-webpack-plugin

Package Overview
Dependencies
291
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    css-chunks-html-webpack-plugin

Injecting css chunks extracted using extract-css-chunks-webpack-plugin to HTML for html-webpack-plugin Edit


Version published
Maintainers
1
Created

Readme

Source

css-chunks-html-webpack-plugin

Plugin 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.

Version

The current version is incompatible with Webpack 3 or older. In order to use this plugin with Webpack 3, use css-chunks-html-webpack-plugin@0.1.0

npm install --save-dev css-chunks-html-webpack-plugin@0.1.0
npm install --save-dev css-chunks-html-webpack-plugin \
 mini-css-extract-plugin babel-plugin-dual-import \
 html-webpack-plugin

webpack.config.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()],
};

Configuration

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 adding chunks paths using custom template for HtmlWebpackPlugin (default true)

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):

<script type="text/javascript">
    window.__CSS_CHUNKS__ = JSON.parse('<%= JSON.stringify(htmlWebpackPlugin.files.cssHash) %>')
</script>

By default, it will inject script tag into <head>. If you want to inject the script tag with window.__CSS_CHUNKS__ into <body> set inject: 'body',

Example

There is a basic example of usage in examples

Contribution

You're free to contribute to this project by submitting issues and/or pull requests.

License

This project is licensed under MIT.

Keywords

FAQs

Last updated on 21 Apr 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc