diff --git a/README.md b/README.md index ca3a5517..934a27a0 100644 --- a/README.md +++ b/README.md @@ -1,57 +1,58 @@ -
- - - - -

extract-css-chunks-webpack-plugin

-
- -[![npm][npm]][npm-url] -[![node][node]][node-url] -[![deps][deps]][deps-url] -[![tests][tests]][tests-url] -[![coverage][cover]][cover-url] -[![chat][chat]][chat-url] -[![size][size]][size-url] +If you like our work, check out our Redux-based router redux-first-router or its sucessor which, Rudy # extract-css-chunks-webpack-plugin -This plugin extracts CSS into separate files. It creates a CSS file per JS file which contains CSS. It supports On-Demand-Loading of CSS and SourceMaps. +

+ + Version + -It builds on top of a new webpack v4 feature (module types) and requires webpack 4 to work. + + Build Status + -Compared to the extract-text-webpack-plugin: + + Downloads + -- Async loading -- No duplicate compilation (performance) -- Easier to use -- Specific to CSS + + License + + + + License + +

-## Getting Started +

🍾🍾🍾It's our absolute pleasure to announce Webpack 4 Support πŸš€πŸš€πŸš€

-To begin, you'll need to install `extract-css-chunks-webpack-plugin`: +> **HEADLINES (May 2018): Now Independently supports Webpack 4:** +> Yep that's right. The universal family is now fully Webpack 4. Thank you to all our users for your loyalty and patience! If you love Universal, then you are gonna fall head over heels when we bring out the main course! -```bash -npm install --save-dev extract-css-chunks-webpack-plugin -``` +So... why did we rebuild `extract-css-chunks`? What does it offer? -It's recommended to combine `extract-css-chunks-webpack-plugin` with the [`css-loader`](https://github.com/webpack-contrib/css-loader) +It's got all the goodness of `mini-css-extract-plugin` but with 2 gleaming, sought after benefits. -Then add the loader and the plugin to your `webpack` config. For example: +Compared to the existing loaders, we are offering a single solution as opposed to needing to depend on multiple loaders to cater for different features: -**style.css** +## Perks -```css -body { - background: green; -} -``` +- **HMR:** It also has first-class support for **Hot Module Replacement** across ALL those css files/chunks!!! +- cacheable stylesheets +- smallest total bytes sent compared to "render-path" css-in-js solutions that include your CSS definitions in JS +- Faster than the V2! +- Async loading +- No duplicate compilation (performance) +- Easier to use +- Specific to CSS +- SSR Friendly development build, focused on frontend DX +- Works seamlessly with the Universal family +- Works fantastically as a standalone style loader (You can use it for any webpack project! with no extra dependencies!) +- Async styles do not render block webkit browsers, if you use the `insert` option -**component.js** +Additionally, if you are already a user of the universal family -- we will be waving goodbye to the mandatory `window.__CSS_CHUNKS__`. -```js -import './style.css'; -``` +The functionality is still available to you via chunk flushing, and it can come in super handy when needing to easily resolve style assets as urls that might need to be passed to a third party. **webpack.config.js** @@ -63,6 +64,7 @@ module.exports = { module: { rules: [ { + test: /\.css$/i, test: /\.css$/i, use: [ExtractCssChunks.loader, 'css-loader'], }, @@ -317,7 +319,7 @@ module.exports = { The `extract-css-chunks-webpack-plugin` supports hot reloading of actual css files in development. Some options are provided to enable HMR of both standard stylesheets and locally scoped CSS or CSS modules. -Below is an example configuration of mini-css for HMR use with CSS modules. +Below is an example configuration of `extract-css-chunks` for HMR use with CSS modules. While we attempt to hmr css-modules. It is not easy to perform when code-splitting with custom chunk names. `reloadAll` is an option that should only be enabled if HMR isn't working correctly. @@ -583,7 +585,7 @@ module.exports = { Type: `String|Function` Default: `head` -By default, the `mini-css-extract-plugin` appends styles (`` elements) to `document.head` of the current `window`. +By default, the `extract-css-chunks-plugin` appends styles (`` elements) to `document.head` of the current `window`. However in some circumstances it might be necessary to have finer control over the append target or even delay `link` elements instertion. For example this is the case when you asynchronously load styles for an application that runs inside of an iframe. In such cases `insert` can be configured to be a function or a custom selector. @@ -594,7 +596,7 @@ If you target an [iframe](https://developer.mozilla.org/en-US/docs/Web/API/HTMLI Allows to configure a [CSS selector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector) that will be used to find the element where to append the styles (`link` elements). ```js -new MiniCssExtractPlugin({ +new ExtractCssChunksPlugin({ insert: '#my-container', }); ``` @@ -610,7 +612,7 @@ Allows to override default behavior and insert styles at any position. > ⚠ The `insert` function is serialized to string and passed to the plugin. This means that it won't have access to the scope of the webpack configuration module. ```js -new MiniCssExtractPlugin({ +new ExtractCssChunksPlugin({ insert: function insert(linkTag) { const reference = document.querySelector('#some-element'); if (reference) {