diff --git a/.editorconfig b/.editorconfig
index 4d3466a5..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 = tab
-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
new file mode 100644
index 00000000..8477d2ab
--- /dev/null
+++ b/.eslintignore
@@ -0,0 +1,6 @@
+/coverage
+/dist
+/node_modules
+/test/fixtures
+/test/cases/*/expected
+/test/js
diff --git a/.eslintrc b/.eslintrc
deleted file mode 100644
index 49060abb..00000000
--- a/.eslintrc
+++ /dev/null
@@ -1,13 +0,0 @@
-{
- "env": {
- "node": true,
- "es6": true,
- },
- "rules": {
- "strict": 0,
- "curly": 0,
- "quotes": 0,
- "no-shadow": 0,
- "no-underscore-dangle": 0
- }
-}
diff --git a/.eslintrc.js b/.eslintrc.js
new file mode 100644
index 00000000..c897f8ee
--- /dev/null
+++ b/.eslintrc.js
@@ -0,0 +1,5 @@
+module.exports = {
+ 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/CODEOWNERS b/.github/CODEOWNERS
new file mode 100644
index 00000000..57da4905
--- /dev/null
+++ b/.github/CODEOWNERS
@@ -0,0 +1,2 @@
+# extract-css-chunks-webpack-plugin maintainers
+* @ScriptedAlchemy
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 e8c5dd92..bc4f57a7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,11 +1,18 @@
-/node_modules
-
-/example/assets
-
-/test/js
+logs
+*.log
+npm-debug.log*
+.eslintcache
/coverage
-
-/.idea
-
+/dist
+/test/js
+/local
+/reports
+/node_modules
.DS_Store
-npm-debug.log
+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 f0064cc0..1baef1c3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,59 +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.
-
-# [2.1.0](https://github.com/webpack/extract-text-webpack-plugin/compare/v2.0.0...v2.1.0) (2017-03-05)
+## [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
-* The plugin **filename** accepts a function now. [c9a19ad](https://github.com/webpack-contrib/extract-text-webpack-plugin/commit/c9a19ad), closes [#423](https://github.com/webpack-contrib/extract-text-webpack-plugin/pull/423)
+* 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)
-
-# [2.0.0](https://github.com/webpack/extract-text-webpack-plugin/compare/v2.0.0-rc.3...v2.0.0) (2017-02-24)
-
-# [2.0.0-rc.2](https://github.com/webpack/extract-text-webpack-plugin/compare/v2.0.0-rc.1...v2.0.0-rc.2) (2017-01-28)
+### Bug Fixes
+
+* 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
-* **schema:** allow `extract` to accept omit/remove flags ([8ce93d5](https://github.com/webpack/extract-text-webpack-plugin/commit/8ce93d5)), closes [#371](https://github.com/webpack/extract-text-webpack-plugin/issues/371)
-* **schema:** connect loader schema with the code properly ([03bb4aa](https://github.com/webpack/extract-text-webpack-plugin/commit/03bb4aa))
-* **schema:** emit proper error messages ([70cbd4b](https://github.com/webpack/extract-text-webpack-plugin/commit/70cbd4b))
+* 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
-* **errors:** show nicer errors if there are extra fields ([76a171d](https://github.com/webpack/extract-text-webpack-plugin/commit/76a171d))
+* 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))
-
-# [2.0.0-rc.1](https://github.com/webpack/extract-text-webpack-plugin/compare/v2.0.0-rc.0...v2.0.0-rc.1) (2017-01-28)
+## [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
-* **options:** pass proper loader options to children ([#266](https://github.com/webpack/extract-text-webpack-plugin/issues/266)) ([6abf42d](https://github.com/webpack/extract-text-webpack-plugin/commit/6abf42d))
+* 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
-
-# [2.0.0-rc.0](https://github.com/webpack/extract-text-webpack-plugin/compare/v2.0.0-beta.5...v2.0.0-rc.0) (2017-01-26)
+* 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))
-### Bug Fixes
-* **readme:** Incorrect loader configuration ([e477cc7](https://github.com/webpack/extract-text-webpack-plugin/commit/e477cc7))
+
+# [0.6.0](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/compare/v0.5.0...v0.6.0) (2019-04-10)
### Features
-* **extract:** return an array of loader objects ([#343](https://github.com/webpack/extract-text-webpack-plugin/issues/343)) ([74b86e0](https://github.com/webpack/extract-text-webpack-plugin/commit/74b86e0))
+* 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))
+
+
+
+
+# [0.5.0](https://github.com/webpack-contrib/extract-css-chunks-webpack-plugin/compare/v0.4.5...v0.5.0) (2018-12-07)
+
+
+### Features
+
+* 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 / --
+==================
+
+ * Bug fix -
+ * Feature -
+ * Chore -
+ * Docs -
diff --git a/ExtractedModule.js b/ExtractedModule.js
deleted file mode 100644
index 38207a8d..00000000
--- a/ExtractedModule.js
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Tobias Koppers @sokra
-*/
-var SourceMapSource = require("webpack-sources").SourceMapSource;
-var RawSource = require("webpack-sources").RawSource;
-
-function ExtractedModule(identifier, originalModule, source, sourceMap, addtitionalInformation, prevModules) {
- this._identifier = identifier;
- this._originalModule = originalModule;
- this._source = source;
- this._sourceMap = sourceMap;
- this._prevModules = prevModules;
- this.addtitionalInformation = addtitionalInformation;
- this.chunks = [];
-}
-module.exports = ExtractedModule;
-
-ExtractedModule.prototype.getOrder = function() {
- // http://stackoverflow.com/a/14676665/1458162
- return /^@import url/.test(this._source) ? 0 : 1;
-};
-
-ExtractedModule.prototype.addChunk = function(chunk) {
- var idx = this.chunks.indexOf(chunk);
- if(idx < 0)
- this.chunks.push(chunk);
-};
-
-ExtractedModule.prototype.removeChunk = function(chunk) {
- var idx = this.chunks.indexOf(chunk);
- if(idx >= 0) {
- this.chunks.splice(idx, 1);
- chunk.removeModule(this);
- return true;
- }
- return false;
-};
-
-ExtractedModule.prototype.rewriteChunkInReasons = function(oldChunk, newChunks) { };
-
-ExtractedModule.prototype.identifier = function() {
- return this._identifier;
-};
-
-ExtractedModule.prototype.source = function() {
- if(this._sourceMap)
- return new SourceMapSource(this._source, null, this._sourceMap);
- else
- return new RawSource(this._source);
-};
-
-ExtractedModule.prototype.getOriginalModule = function() {
- return this._originalModule;
-};
-
-ExtractedModule.prototype.getPrevModules = function() {
- return this._prevModules;
-};
-
-ExtractedModule.prototype.addPrevModules = function(prevModules) {
- prevModules.forEach(function(m) {
- if(this._prevModules.indexOf(m) < 0)
- this._prevModules.push(m);
- }, this);
-};
-
-ExtractedModule.prototype.setOriginalModule = function(originalModule) {
- this._originalModule = originalModule;
-};
diff --git a/LICENSE b/LICENSE
index 8c11fc72..dfc572fb 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,5 @@
Copyright JS Foundation and other contributors
+Copyright Zack Jackson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
diff --git a/OrderUndefinedError.js b/OrderUndefinedError.js
deleted file mode 100644
index cedec9a3..00000000
--- a/OrderUndefinedError.js
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Tobias Koppers @sokra
-*/
-function OrderUndefinedError(module) {
- Error.call(this);
- Error.captureStackTrace(this, OrderUndefinedError);
- this.name = "OrderUndefinedError";
- this.message = "Order in extracted chunk undefined";
- this.module = module;
-}
-module.exports = OrderUndefinedError;
-
-OrderUndefinedError.prototype = Object.create(Error.prototype);
diff --git a/README.md b/README.md
index 89e9f7b3..112bbdc2 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,4 @@
-
-
-
-
+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 @@
-
+
@@ -17,245 +14,606 @@
+
+
+
+
+
+
+
+
-> **UPDATE (July 7th):** [babel-plugin-dual-import](https://github.com/faceyspacey/babel-plugin-dual-import) is now required to asynchronously import both css + js. *Much Faster Builds!* You likely want to read [its intro article](https://medium.com/@faceyspacey/webpacks-import-will-soon-fetch-js-css-here-s-how-you-do-it-today-4eb5b4929852).
+
πΎπΎπΎIt's our absolute pleasure to announce Webpack 4 Support πππ
-> **UPDATE (July 26th):** [babel-plugin-universal-import](https://github.com/faceyspacey/babel-plugin-universal-import) is what to use if you're using *React Universal Component*.
+> **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!
-Like `extract-text-webpack-plugin`, but creates multiple css files (one per chunk). Then, as part of server side rendering, you can deliver just the css chunks needed by the current request. The result is the most minimal CSS initially served compared to emerging "render path" solutions.
+So... why did we rebuild `extract-css-chunks-webpack-plugin`? What does it offer?
-For a demo, `git clone`: [universal-demo](https://github.com/faceyspacey/universal-demo)
+It's got all the goodness of `mini-css-extract-plugin` but with 2 gleaming, sought after benefits.
-*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)
+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
-## Recommended Installation
-```
-yarn add react-universal-component webpack-flush-chunks
-yarn add --dev extract-css-chunks-webpack-plugin babel-plugin-universal-import
-```
+- **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.config.js**
-*.babelrc:*
```js
-{
- "plugins": ["universal-import"]
-}
+const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
+
+module.exports = {
+ plugins: [new ExtractCssChunks()],
+ module: {
+ rules: [
+ {
+ test: /\.css$/i,
+ use: [ExtractCssChunks.loader, 'css-loader'],
+ },
+ ],
+ },
+};
```
-*webpack.config.js:*
+## Options
+
+### `publicPath`
+
+Type: `String|Function`
+Default: the `publicPath` in `webpackOptions.output`
+
+Specifies a custom public path for the target file(s).
+
+#### `String`
+
+**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.extract({
- use: {
- loader: 'css-loader',
+ use: [
+ {
+ loader: ExtractCssChunks.loader,
options: {
- modules: true,
- localIdentName: '[name]__[local]--[hash:base64:5]'
- }
- }
- })
- }
- ]
+ publicPath: '/public/path/to/',
+ },
+ },
+ 'css-loader',
+ ],
+ },
+ ],
},
- plugins: [
- new ExtractCssChunks,
- ]
-}
+};
```
-## Desired Output
-Here's the sort of CSS you can expect to serve:
+#### `Function`
-```
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+**webpack.config.js**
+
+```js
+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',
+ ],
+ },
+ ],
+ },
+};
```
-[webpack-flush-chunks](https://github.com/faceyspacey/webpack-flush-chunks) will scoop up the exact stylesheets to embed in your response. It essentially automates producing the above.
+### `esModule`
-Here's how you do it:
+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:
+
+**webpack.config.js**
-*src/components/App.js:*
```js
-const UniversalComponent = universal(props => import(`./${props.page}`))
+const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
-
+module.exports = {
+ plugins: [new ExtractCssChunks()],
+ module: {
+ rules: [
+ {
+ test: /\.css$/i,
+ use: [
+ {
+ loader: ExtractCssChunks.loader,
+ options: {
+ esModule: true,
+ },
+ },
+ 'css-loader',
+ ],
+ },
+ ],
+ },
+};
```
-*server/render.js:*
+## Examples
+
+### Minimal example
+
+**webpack.config.js**
+
```js
-import { flushChunkNames } from 'react-universal-component/server'
-import flushChunks from 'webpack-flush-chunks'
-
-const app = ReactDOMServer.renderToString()
-const { js, styles, cssHash } = flushChunks(webpackStats, {
- chunkNames: flushChunkNames()
-})
-
-res.send(`
-
-
-
- ${styles}
-
-
-
${app}
- ${cssHash}
- ${js}
-
-
-`)
+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: [
+ {
+ loader: ExtractCssChunks.loader,
+ options: {
+ // you can specify a publicPath here
+ // by default it uses publicPath in webpackOptions.output
+ publicPath: '../',
+ hmr: process.env.NODE_ENV === 'development',
+ },
+ },
+ 'css-loader',
+ ],
+ },
+ ],
+ },
+};
```
-***As for asynchronous calls to `import()` on user navigation,*** [babel-plugin-universal-import](https://github.com/faceyspacey/babel-plugin-universal-import) is required if you're using [react-universal-component](https://github.com/faceyspacey/react-universal-component). And if you aren't, you must use: [babel-plugin-dual-import](https://github.com/faceyspacey/babel-plugin-dual-import).
+### The `publicPath` option as function
-These babel plugins request both your js + your css. *Very Nice!* This is the new feature of the 2.0. Read *Sokra's* (author of webpack) article on how [on how this is the future of CSS for webpack](https://medium.com/webpack/the-new-css-workflow-step-1-79583bd107d7). Use this and be in the future today.
+**webpack.config.js**
-## 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 V1!
+```js
+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) => {
+ // publicPath is the relative path of the resource to the context
+ // e.g. for ./css/admin/main.css the publicPath will be ../../
+ // while for ./css/main.css the publicPath will be ../
+ return path.relative(path.dirname(resourcePath), context) + '/';
+ },
+ },
+ },
+ 'css-loader',
+ ],
+ },
+ ],
+ },
+};
+```
+
+### Advanced configuration example
+This plugin should be used only on `production` builds without `style-loader` in the loaders chain, especially if you want to have HMR in `development`.
+Here is an example to have both HMR in `development` and your styles extracted in a file for `production` builds.
-## API
-You can pass the same options as `extract-text-webpack-plugin` to `new ExtractCssChunks`, such as:
+(Loaders options left out for clarity, adapt accordingly to your needs.)
+
+**webpack.config.js**
+
+```js
+const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
+const devMode = process.env.NODE_ENV !== 'production';
-```javascript
-new ExtractCssChunk({
- filename: '[name].[contenthash].css'
-})
+module.exports = {
+ plugins: [
+ new ExtractCssChunks({
+ // Options similar to the same options in webpackOptions.output
+ // both options are optional
+ filename: devMode ? '[name].css' : '[name].[hash].css',
+ chunkFilename: devMode ? '[id].css' : '[id].[hash].css',
+ }),
+ ],
+ module: {
+ rules: [
+ {
+ test: /\.(sa|sc|c)ss$/,
+ use: [
+ {
+ loader: ExtractCssChunks.loader,
+ options: {
+ hmr: process.env.NODE_ENV === 'development',
+ },
+ },
+ 'css-loader',
+ 'postcss-loader',
+ 'sass-loader',
+ ],
+ },
+ ],
+ },
+};
```
-Keep in mind, by default `[name].css` is used when `process.env.NODE_ENV === 'development'` and `[name].[contenthash].css` during production, so you can likely forget about having to pass anything.
+### Hot Module Reloading (HMR)
-The 2 exceptions are: `allChunks` will no longer do anything, and `fallback` will no longer do anything when passed to to `extract`. Basically just worry about passing your `css-loader` string and `localIdentName` π€
+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 `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.
+The core challenge with css-modules is that when code-split, the chunk ids can and do end up different compared to the filename.
-### HMR Pitfall
+**webpack.config.js**
-The most common workflow when working with webpack is to write a "development" / "production" value in to the
-'process.env.NODE_ENV' namespace, typically, using webpack's built-in "DefinePlugin" plugin. e.g:
+```js
+const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
-```javascript
-new webpack.DefinePlugin( {
- 'process.env': {
- NODE_ENV: `"${config.devMode ? 'development' : 'production'}"`,
+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: {
+ // only enable hot in development
+ hmr: process.env.NODE_ENV === 'development',
+ // if hmr does not work, this is a forceful method.
+ reloadAll: true,
+ },
+ },
+ 'css-loader',
+ ],
},
-} )
+ ],
+ },
+};
```
-The value set by the aformentioned plugin will only be available in the runtime ( when webpack's javascript output is excuted ).
-In order for this plugin to work with hot module reloading, The npm script / gulp task / grunt task etc, should be invoked with the same environment variable as shown above.
-For example, when running the build using some form of npm script:
+### Minimizing For Production
-```json
-{
- "scripts": {
- "build": "cross-env NODE_ENV=development webpack --config build/webpack.config.js"
- }
-}
+To minify the output, use a plugin like [optimize-css-assets-webpack-plugin](https://github.com/NMFR/optimize-css-assets-webpack-plugin).
+Setting `optimization.minimizer` overrides the defaults provided by webpack, so make sure to also specify a JS minimizer:
+
+**webpack.config.js**
+
+```js
+const TerserJSPlugin = require('terser-webpack-plugin');
+const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
+const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
+
+module.exports = {
+ optimization: {
+ minimizer: [new TerserJSPlugin({}), new OptimizeCSSAssetsPlugin({})],
+ },
+ plugins: [
+ new ExtractCssChunks({
+ filename: '[name].css',
+ chunkFilename: '[id].css',
+ }),
+ ],
+ module: {
+ rules: [
+ {
+ test: /\.css$/,
+ use: [ExtractCssChunks.loader, 'css-loader'],
+ },
+ ],
+ },
+};
```
-[cross-env](https://www.npmjs.com/package/cross-env) is optional but recommended.
-## What about Glamorous, Styled Components, Styled-Jsx, Aphrodite, etc?
+### Using preloaded or inlined CSS
+
+The runtime code detects already added CSS via `` or `
+
+
+
+
+
+ Initial CSS: Must be green
+
+
+
Hot Module Replacement
+
RED
+
GREEN
+
BLUE
+
+
+
Hot Module Replacement + CSS modules
+
RED
+
GREEN
+
BLUE
+
+
+
+ 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.
+