All Projects → teamable-software → css-chunks-html-webpack-plugin

teamable-software / css-chunks-html-webpack-plugin

Licence: MIT license
Injecting css chunks extracted using extract-css-chunks-webpack-plugin to HTML for html-webpack-plugin

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to css-chunks-html-webpack-plugin

image-minimizer-webpack-plugin
Webpack loader and plugin to compress images using imagemin
Stars: ✭ 180 (+718.18%)
Mutual labels:  webpack-plugin
bower-resolve-webpack-plugin
Offers an enhanced bower support for enhanced-resolve plugin.
Stars: ✭ 12 (-45.45%)
Mutual labels:  webpack-plugin
loading-screen
🚥Loading screen for webpack plugin inspired by Nuxt.js's loading screen
Stars: ✭ 56 (+154.55%)
Mutual labels:  webpack-plugin
crx-webpack-plugin
A webpack plugin to package chrome extensions (crx) post build
Stars: ✭ 21 (-4.55%)
Mutual labels:  webpack-plugin
config-webpack-plugin
💫 Merge one or more configuration files together with environment variables too.
Stars: ✭ 18 (-18.18%)
Mutual labels:  webpack-plugin
chicio.github.io
👻 Fabrizio Duroni (me 😄) personal website. Created using GatsbyJS, Styled Components, Storybook, Typescript, tsParticles, GitHub pages, Github Actions, Upptime.
Stars: ✭ 20 (-9.09%)
Mutual labels:  webpack-plugin
asset-map-webpack-plugin
Webpack plugin that creates a map of assets to public url slug for server agnostic usage.
Stars: ✭ 14 (-36.36%)
Mutual labels:  webpack-plugin
html-webpack-exclude-assets-plugin
Add the ability to exclude assets based on RegExp patterns
Stars: ✭ 50 (+127.27%)
Mutual labels:  html-webpack-plugin
warnings-to-errors-webpack-plugin
a webpack plugin that can recognize every warning as errors.
Stars: ✭ 17 (-22.73%)
Mutual labels:  webpack-plugin
link-media-html-webpack-plugin
parses CSS filenames to automatically apply media HTML attribute to link elements
Stars: ✭ 15 (-31.82%)
Mutual labels:  html-webpack-plugin
webpack-demos
webpack小练习
Stars: ✭ 17 (-22.73%)
Mutual labels:  webpack-plugin
mock-webpack-plugin
A webpack plugin that starts a json mock server
Stars: ✭ 21 (-4.55%)
Mutual labels:  webpack-plugin
remove-files-webpack-plugin
A plugin for webpack that removes files and folders before and after compilation.
Stars: ✭ 48 (+118.18%)
Mutual labels:  webpack-plugin
del-webpack-plugin
A file plugin help you remove old files after webpack (v5) bundling
Stars: ✭ 43 (+95.45%)
Mutual labels:  webpack-plugin
webpack-stats-diff-plugin
Webpack plugin for reporting changes in bundle sizes across builds
Stars: ✭ 63 (+186.36%)
Mutual labels:  webpack-plugin
pxtorem-webpack-plugin
A webpack plugin for generating rem for stylesheet and inject auto calculate scripts.
Stars: ✭ 24 (+9.09%)
Mutual labels:  webpack-plugin
targets-webpack-plugin
Webpack plugin for transcompilig final bundles so they support legacy browsers
Stars: ✭ 15 (-31.82%)
Mutual labels:  webpack-plugin
size-plugin-bot
A Github bot for size-plugin
Stars: ✭ 76 (+245.45%)
Mutual labels:  webpack-plugin
monaco-editor-esm-webpack-plugin
No description or website provided.
Stars: ✭ 25 (+13.64%)
Mutual labels:  webpack-plugin
webpack-alioss-upload-plugin
A flexible webpack plugin to upload files to aliyun oss, which supports multiple optional upload methods and parameters.
Stars: ✭ 14 (-36.36%)
Mutual labels:  webpack-plugin

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 [email protected]

npm install --save-dev [email protected]

Recommended Installation

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].