diff --git a/.babelrc b/.babelrc
deleted file mode 100644
index b3bfd2cb..00000000
--- a/.babelrc
+++ /dev/null
@@ -1,36 +0,0 @@
-{
- "presets": [
- [
- "env",
- {
- "useBuiltIns": true,
- "targets": {
- "node": "6.11.5",
- "browsers": "cover 99.5%"
- },
- "exclude": [
- "transform-async-to-generator",
- "transform-regenerator"
- ]
- }
- ]
- ],
- "plugins": [
- [
- "transform-object-rest-spread",
- {
- "useBuiltIns": true
- }
- ]
- ],
- "env": {
- "test": {
- "presets": [
- "env"
- ],
- "plugins": [
- "transform-object-rest-spread"
- ]
- }
- }
-}
diff --git a/.editorconfig b/.editorconfig
index 79664df2..9f89f364 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,17 +1,13 @@
-# EditorConfig is awesome: http://EditorConfig.org
+# editorconfig.org
-# top-most EditorConfig file
-root = true
-
-# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
+indent_style = space
+indent_size = 2
end_of_line = lf
insert_final_newline = true
-indent_style = space
-indent_size = 4
+trim_trailing_whitespace = true
-# Matches the exact files either package.json or .travis.yml
-[{package.json,.travis.yml}]
-indent_style = space
-indent_size = 2
+[*.md]
+insert_final_newline = true
+trim_trailing_whitespace = false
diff --git a/.eslintignore b/.eslintignore
index 4a868dc8..8477d2ab 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -1 +1,6 @@
-test/js/**/*.js
+/coverage
+/dist
+/node_modules
+/test/fixtures
+/test/cases/*/expected
+/test/js
diff --git a/.eslintrc.js b/.eslintrc.js
index 41c10cb5..c897f8ee 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -1,27 +1,5 @@
module.exports = {
- parser: 'babel-eslint',
- parserOptions: {
- ecmaFeatures: {
- generators: true,
- experimentalObjectRestSpread: true
- },
- sourceType: 'module',
- allowImportExportEverywhere: false
- },
- extends: ['airbnb'],
- env: {
- 'browser': true,
- },
- rules: {
- 'no-param-reassign': 0,
- 'func-names': 0,
- 'no-underscore-dangle': 0,
- 'no-restricted-syntax': 0,
- 'prefer-arrow-callback': 0,
- 'prefer-destructuring': 0,
- 'array-callback-return': 0,
- 'prefer-template': 0,
- 'class-methods-use-this': 0,
- 'no-plusplus': 0
- }
+ root: true,
+ parser: 'babel-eslint',
+ extends: ['@webpack-contrib/eslint-config-webpack', 'prettier'],
};
diff --git a/.gitattributes b/.gitattributes
index 176a458f..c76f8a99 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1 +1,5 @@
+package-lock.json -diff
* text=auto
+test/cases/* eol=lf
+bin/* eol=lf
+yarn.lock -diff
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
deleted file mode 100644
index f0c0b39c..00000000
--- a/.github/PULL_REQUEST_TEMPLATE.md
+++ /dev/null
@@ -1,4 +0,0 @@
-1. [Read and sign the CLA](https://cla.js.foundation/webpack/webpack.js.org). This needs to be done only once. PRs that haven't signed it won't be accepted.
-2. Check out the [development guide](https://webpack.js.org/development/) for the API and development guidelines.
-3. Read through the PR diff carefully as sometimes this can reveal issues. The work will be reviewed, but this can save some effort.
-4. Remove these instructions from your PR as they are for your eyes only.
diff --git a/.gitignore b/.gitignore
index 345c30b8..bc4f57a7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,12 +1,18 @@
-/node_modules
-
-/test/js
+logs
+*.log
+npm-debug.log*
+.eslintcache
/coverage
/dist
-
-.idea
-.eslintcache
-
+/test/js
+/local
+/reports
+/node_modules
.DS_Store
-*.log
-.eslintcache
+Thumbs.db
+.idea
+.vscode
+*.sublime-project
+*.sublime-workspace
+.idea
+*.iml
diff --git a/.npmignore b/.npmignore
index 61a3bec4..3ef3ec08 100644
--- a/.npmignore
+++ b/.npmignore
@@ -1,3 +1,6 @@
example/
test/
.gitattributes
+.git
+.github
+coverage/
diff --git a/.prettierignore b/.prettierignore
new file mode 100644
index 00000000..41ff7724
--- /dev/null
+++ b/.prettierignore
@@ -0,0 +1,7 @@
+/coverage
+/dist
+/node_modules
+/test/fixtures
+/test/cases/*/expected
+/test/js
+CHANGELOG.md
diff --git a/.prettierrc b/.prettierrc
new file mode 100644
index 00000000..e537c8ad
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1,5 @@
+{
+ "singleQuote": true,
+ "trailingComma": "es5",
+ "arrowParens": "always"
+}
diff --git a/.prettierrc.js b/.prettierrc.js
new file mode 100644
index 00000000..1934550a
--- /dev/null
+++ b/.prettierrc.js
@@ -0,0 +1,5 @@
+module.exports = {
+ singleQuote: true,
+ trailingComma: 'es5',
+ arrowParens: 'always',
+};
diff --git a/.snyk b/.snyk
new file mode 100644
index 00000000..5c89b3d5
--- /dev/null
+++ b/.snyk
@@ -0,0 +1,12 @@
+# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
+version: v1.13.5
+ignore: {}
+# patches apply the minimum changes required to fix a vulnerability
+patch:
+ SNYK-JS-LODASH-450202:
+ - webpack-external-import > babel-traverse > lodash:
+ patched: '2019-07-04T06:20:01.150Z'
+ - webpack-external-import > @babel/helper-module-imports > @babel/types > lodash:
+ patched: '2019-07-04T06:20:01.150Z'
+ - webpack-external-import > babel-traverse > babel-types > lodash:
+ patched: '2019-07-04T06:20:01.150Z'
diff --git a/.travis.yml b/.travis.yml
index 1a8fb8d2..2969668d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,11 +1,15 @@
sudo: false
language: node_js
node_js:
- - stable
+ - v10
+before_script:
+ - nvm use v8
+ - yarn --ignore-engines
script:
- - echo success
+ - yarn lint
+ - yarn test
after_success:
- - yarn run semantic-release
+ - npm run semantic-release
branches:
except:
- /^v\d+\.\d+\.\d+$/
@@ -14,6 +18,6 @@ notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/5156be73e058008e1ed2
- on_success: always # options: [always|never|change] default: always
- on_failure: always # options: [always|never|change] default: always
- on_start: never # options: [always|never|change] default: always
+ on_success: always # options: [always|never|change] default: always
+ on_failure: always # options: [always|never|change] default: always
+ on_start: never # options: [always|never|change] default: always
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f471e20f..1baef1c3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,21 +1,151 @@
-# Change Log
+# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
-
-## [3.2.1](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/compare/v3.2.0...v3.2.1) (2018-10-23)
+## [4.9.0](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/compare/v4.8.0...v4.9.0) (2020-12-07)
+
+
+### Features
+
+* adding federated stats ([#303](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/issues/303)) ([c17d755](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/commit/c17d75547a5efb5971d03555163ea4d685080706))
+* adding federated stats ([#304](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/issues/304)) ([1eab2d0](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/commit/1eab2d0b8868837de8f89f68c1ad14be741f3e78))
+
+
+### Bug Fixes
+
+* Check if bestMatch exists before pop() ([#294](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/issues/294)) ([ef82da9](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/commit/ef82da9068bd699344774d39f61b7ead8cf682cb))
+
+### [0.9.0](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/compare/v0.8.2...v0.9.0) (2019-12-20)
+
+
+### Features
+
+* new `esModule` option ([#475](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/475)) ([596e47a](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/596e47a8aead53f9cc0e2b1e09a2c20e455e45c1))
+
+### [0.8.2](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/compare/v0.8.1...v0.8.2) (2019-12-17)
### Bug Fixes
-* CSS HMR Issues ([#114](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/issues/114)) ([ae0f5b1](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/commit/ae0f5b1)), closes [#98](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/issues/98) [#80](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/issues/80) [#116](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/issues/116) [#113](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/issues/113) [#115](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/issues/115) [#113](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/issues/113)
+* context for dependencies ([#474](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/474)) ([0269860](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/0269860adb0eaad477901188eea66693fedf7769))
+
+### [0.8.1](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/compare/v0.8.0...v0.8.1) (2019-12-17)
+
+
+### Bug Fixes
+
+* use filename mutated after instantiation ([#430](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/430)) ([0bacfac](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/0bacfac7ef4a06b4810fbc140875f7a038caa5bc))
+* improve warning of conflict order ([#465](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/465)) ([357d073](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/357d073bf0259f2c44e613ad4dfcbcc8354e4be3))
+* support ES module syntax ([#472](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/472)) ([2f72e1a](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/2f72e1aa267de23f121441714e88406f579e77b2))
+
+## [0.8.0](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/compare/v0.7.0...v0.8.0) (2019-07-16)
+
+
+### Features
+
+* Add ignoreOrder option ([#422](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/422)) ([4ad3373](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/4ad3373))
+
+
+
+## [0.7.0](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/compare/v0.6.0...v0.7.0) (2019-05-27)
+
+
+### Bug Fixes
+
+* do not attempt to reload unrequestable urls ([#378](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/378)) ([44d00ea](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/44d00ea))
+* fix `publicPath` regression ([#384](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/384)) ([582ebfe](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/582ebfe))
+* enable using plugin without defining options ([#393](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/393)) ([a7dee8c](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/a7dee8c))
+* downgrading normalize-url ([#399](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/399)) ([0dafaf6](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/0dafaf6))
+* hmr do not crash on link without href ([#400](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/400)) ([aa9b541](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/aa9b541))
+* hmr reload with invalid link url ([#402](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/402)) ([30a19b0](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/30a19b0))
+
+
+### Features
+
+* add `moduleFilename` option ([#381](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/381)) ([13e9cbf](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/13e9cbf))
+
+
+
+
+# [0.6.0](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/compare/v0.5.0...v0.6.0) (2019-04-10)
+
+
+### Features
+
+* added error code to chunk load Error ([#347](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/347)) ([b653641](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/b653641))
+* adding hot module reloading ([#334](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/334)) ([4ed9c5a](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/4ed9c5a))
+* publicPath can be a function ([#373](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/373)) ([7b1425a](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/7b1425a))
-
-# [3.2.0](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/compare/v3.1.2...v3.2.0) (2018-10-08)
+
+# [0.5.0](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/compare/v0.4.5...v0.5.0) (2018-12-07)
### Features
-* **readme:** Documenting new options that have been added ([#112](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/issues/112)) ([94ee96e](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin/commit/94ee96e))
+* add crossOriginLoading option support ([#313](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/313)) ([ffb0d87](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/ffb0d87))
+
+
+
+
+## [0.4.5](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/compare/v0.4.4...v0.4.5) (2018-11-21)
+
+
+### Bug Fixes
+
+* **index:** allow requesting failed async css files ([#292](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/292)) ([2eb0af5](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/2eb0af5))
+
+
+
+
+## [0.4.4](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/compare/v0.4.3...v0.4.4) (2018-10-10)
+
+
+### Bug Fixes
+
+* **index:** assign empty `module.id` to prevent `contenthash` from changing unnecessarily ([#284](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/284)) ([d7946d0](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/d7946d0))
+
+
+
+
+## [0.4.3](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/compare/v0.4.2...v0.4.3) (2018-09-18)
+
+
+### Bug Fixes
+
+* **loader:** pass `emitFile` to the child compilation (`loaderContext.emitFile`) ([#177](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/177)) ([18c066e](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/18c066e))
+
+
+
+
+## [0.4.2](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/compare/v0.4.0...v0.4.2) (2018-08-21)
+
+
+### Bug Fixes
+
+* use correct order when multiple chunk groups are merged ([#246](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/246)) ([c3b363d](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/c3b363d))
+
+
+
+
+## [0.4.1](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/compare/v0.4.0...v0.4.1) (2018-06-29)
+
+
+### Bug Fixes
+
+* CSS ordering with multiple entry points ([#130](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/issues/130)) ([79373eb](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/commit/79373eb))
+
+
+
+# Change Log
+
+All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
+
+x.x.x / Hot Module Replacement Hot Module Replacement + CSS modules
+ Lazy CSS: Must be red, but turn green when
+ .
+
+ But turn orange, when
+ . Additional
+ clicks have no effect.
+
+ Refresh and press buttons in reverse order: This should turn green
+ instead.
+
+ Lazy CSS: Turn off the network and
+ .
+ An error should have appeared.
+ Now if you turn the network back on and click it again, it should turn
+ aqua.
+ Preloaded CSS: Must be green.
+ displays
+ an alert and should turn red.
+ Preloaded inlined CSS: Must be green.
+ displays
+ an alert and should turn red.
+ CrossOriginLoading Option: Must be red.
+ loads chunks with crossorigin
+ attribute and should turn green.
+
-
-
+If you like our work, check out our Redux-based router redux-first-router or its sucessor which, Rudy
# extract-css-chunks-webpack-plugin
@@ -9,7 +6,7 @@
-
+
@@ -29,383 +26,594 @@
πΎπΎπΎIt's our absolute pleasure to announce Webpack 4 Support πππ
-> **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!
+> **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!
-So... why did we rebuild `extract-css-chunks`? What does it offer?
+So... why did we rebuild `extract-css-chunks-webpack-plugin`? What does it offer?
-It's got all the goodness of `mini-css-extract-plugin` but with 2 gleaming, sought after benefits.
+It's got all the goodness of `mini-css-extract-plugin` but with 2 gleaming, sought after benefits.
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:
## Perks
-* **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!)
-
-Additionally, if you are already a user of the universal family -- we will be waving goodbye to the mandatory ```window.__CSS_CHUNKS__```.
+
+- **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
+
+Additionally, if you are already a user of the universal family -- we will be waving goodbye to the mandatory `window.__CSS_CHUNKS__`.
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 4 Standalone Installation:
+**webpack.config.js**
-If you are just looking for something that works like `mini-css-extract-plugin` but with HMR, then look no further.
+```js
+const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
-NOTE: We have aligned out loader implementation to be the same as `mini-css-extract-plugin`
+module.exports = {
+ plugins: [new ExtractCssChunks()],
+ module: {
+ rules: [
+ {
+ test: /\.css$/i,
+ use: [ExtractCssChunks.loader, 'css-loader'],
+ },
+ ],
+ },
+};
+```
-**If you already use `mini-css-extract-plugin`, then you can just change the `require` statement - it's that easy**
+## Options
-```
-yarn add --dev extract-css-chunks-webpack-plugin
-```
+### `publicPath`
+
+Type: `String|Function`
+Default: the `publicPath` in `webpackOptions.output`
+
+Specifies a custom public path for the target file(s).
+
+#### `String`
+
+**webpack.config.js**
-*webpack.config.js:*
```js
-const ExtractCssChunks = require("extract-css-chunks-webpack-plugin")
+const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
module.exports = {
+ plugins: [
+ new ExtractCssChunks({
+ // Options similar to the same options in webpackOptions.output
+ // both options are optional
+ filename: '[name].css',
+ chunkFilename: '[id].css',
+ }),
+ ],
module: {
rules: [
{
test: /\.css$/,
use: [
- ExtractCssChunks.loader,
- "css-loader"
- ]
- }
- ]
+ {
+ loader: ExtractCssChunks.loader,
+ options: {
+ publicPath: '/public/path/to/',
+ },
+ },
+ 'css-loader',
+ ],
+ },
+ ],
},
- plugins: [
- new ExtractCssChunks(
- {
- // Options similar to the same options in webpackOptions.output
- // both options are optional
- filename: "[name].css",
- chunkFilename: "[id].css",
- hot: true, // if you want HMR - we try to automatically inject hot reloading but if it's not working, add it to the config
- orderWarning: true, // Disable to remove warnings about conflicting order between imports
- reloadAll: true, // when desperation kicks in - this is a brute force HMR flag
- cssModules: true // if you use cssModules, this can help.
- }
- ),
- ]
-}
+};
```
-*webpack.server.config.js*
+#### `Function`
-The server needs to be handled differently, we still want one chunk. Luckily webpack 4 supports **LimitChunkCountPlugin**
+**webpack.config.js**
```js
-new webpack.optimize.LimitChunkCountPlugin({
- maxChunks: 1
-})
-```
+const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
+module.exports = {
+ plugins: [
+ new ExtractCssChunks({
+ // Options similar to the same options in webpackOptions.output
+ // both options are optional
+ filename: '[name].css',
+ chunkFilename: '[id].css',
+ }),
+ ],
+ module: {
+ rules: [
+ {
+ test: /\.css$/,
+ use: [
+ {
+ loader: ExtractCssChunks.loader,
+ options: {
+ publicPath: (resourcePath, context) => {
+ return path.relative(path.dirname(resourcePath), context) + '/';
+ },
+ },
+ },
+ 'css-loader',
+ ],
+ },
+ ],
+ },
+};
+```
-### What about Webpack 3?
-This is a breaking change. The entire loader has been fundamentally rewritten specifically for Webpack 4. Aiming to support our existing user base, allowing them to upgrade their infrastructure to support Webpack 4 based universally code-split server-side rendered react applications.
-
-There have been some challenges along the way since the release of webpack 4. Ultimately the only remaining hurdle is code split, async style loading.
-
-If you do need Webpack 3, make sure to stick with the latest `v2.x.x` release. `v3.x.x` is only intended for users with Webpack 4
+### `esModule`
+Type: `Boolean`
+Default: `false`
+By default, `extract-css-chunks-webpack-plugin` generates JS modules that use the CommonJS modules syntax.
+There are some cases in which using ES modules is beneficial, like in the case of [module concatenation](https://webpack.js.org/plugins/module-concatenation-plugin/) and [tree shaking](https://webpack.js.org/guides/tree-shaking/).
+You can enable a ES module syntax using:
-*Note: this is a companion package to:*
-- [webpack-flush-chunks](https://github.com/faceyspacey/webpack-flush-chunks)
-- [react-universal-component](https://github.com/faceyspacey/react-universal-component)
-- [babel-plugin-universal-import](https://github.com/faceyspacey/babel-plugin-universal-import) ***or*** [babel-plugin-dual-import](https://github.com/faceyspacey/babel-plugin-dual-import)
+**webpack.config.js**
+```js
+const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
-## Recommended Installation For Universal
-```
-yarn add react-universal-component webpack-flush-chunks
-yarn add --dev extract-css-chunks-webpack-plugin babel-plugin-universal-import
+module.exports = {
+ plugins: [new ExtractCssChunks()],
+ module: {
+ rules: [
+ {
+ test: /\.css$/i,
+ use: [
+ {
+ loader: ExtractCssChunks.loader,
+ options: {
+ esModule: true,
+ },
+ },
+ 'css-loader',
+ ],
+ },
+ ],
+ },
+};
```
-*.babelrc:*
-```js
-{
- "plugins": ["universal-import"]
-}
-```
-The main thing is you need to cater to the new chunking system of webpack!
-With **webpack.optimize.CommonsChunkPlugin** plugin no longer part of Webpack 4, we need another way to define the code-splitting. Luckily we have `optimization` configs built into webpack now
+## Examples
+
+### Minimal example
-> There are more aggressive ways to code split, thanks to webpack 4. Check out the RUC Readme if you are looking for a more aggressive code split optimization configuration. These are just examples, you should be able to configure them as you see fit
+**webpack.config.js**
-*webpack.config.js:*
```js
-const ExtractCssChunks = require("extract-css-chunks-webpack-plugin")
+const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
module.exports = {
+ plugins: [
+ new ExtractCssChunks({
+ // Options similar to the same options in webpackOptions.output
+ // all options are optional
+ filename: '[name].css',
+ chunkFilename: '[id].css',
+ ignoreOrder: false, // Enable to remove warnings about conflicting order
+ }),
+ ],
module: {
rules: [
{
test: /\.css$/,
use: [
- ExtractCssChunks.loader,
{
- loader: 'css-loader',
+ loader: ExtractCssChunks.loader,
options: {
- modules: true,
- localIdentName: '[name]__[local]--[hash:base64:5]',
+ // you can specify a publicPath here
+ // by default it uses publicPath in webpackOptions.output
+ publicPath: '../',
+ hmr: process.env.NODE_ENV === 'development',
},
},
+ 'css-loader',
],
},
],
},
- optimization: {
- // FOR PRODUCTION
- minimizer: [
- new UglifyJSPlugin({
- uglifyOptions: {
- output: {
- comments: false,
- ascii_only: true
- },
- compress: {
- comparisons: false
- }
- }
- })
- ],
- // END
- // NEEDED BOTH IN PROD AND DEV BUILDS
- runtimeChunk: {
- name: 'bootstrap'
- },
- splitChunks: {
- chunks: 'initial',
- cacheGroups: {
- vendors: {
- test: /[\\/]node_modules[\\/]/,
- name: 'vendor'
- }
- }
- }
- },
- plugins: [
- new ExtractCssChunks({hot:true, cssModules: true}), //if you want HMR - we try to automatically inject hot reloading but if it's not working, add it to the config
- ]
};
```
-## Desired Output
-Here's the sort of CSS you can expect to serve:
-
-```
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-```
-
-If you need to resolve your stylesheets on the client side, for whatever reason.
-
-[webpack-flush-chunks](https://github.com/faceyspacey/webpack-flush-chunks) will scoop up the exact stylesheets to embed in your response. It will give you an object which can be embedded on page
-
-Here's how you do it:
+### The `publicPath` option as function
+**webpack.config.js**
-*src/components/App.js:*
```js
-const UniversalComponent = universal(props => import(`./${props.page}`))
+const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
-