From c5b52ac3791cb6d9134b7966fc38502351151071 Mon Sep 17 00:00:00 2001
From: cap-Bernardito
Date: Wed, 15 Jul 2020 19:19:12 +0300
Subject: [PATCH 1/9] feat: esModule export named
---
README.md | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 94b64786..b344a523 100644
--- a/README.md
+++ b/README.md
@@ -118,6 +118,7 @@ module.exports = {
| **[`importLoaders`](#importloaders)** | `{Number}` | `0` | Enables/Disables or setups number of loaders applied before CSS loader |
| **[`onlyLocals`](#onlylocals)** | `{Boolean}` | `false` | Export only locals |
| **[`esModule`](#esmodule)** | `{Boolean}` | `false` | Use ES modules syntax |
+| **[`namedExport`](#namedExport)** | `{Boolean}` | `false` | Use ES modules named export |
### `url`
@@ -531,7 +532,6 @@ module.exports = {
mode: 'local',
exportGlobals: true,
localIdentName: '[path][name]__[local]--[hash:base64:5]',
- localsConvention: 'camelCase',
context: path.resolve(__dirname, 'src'),
hashPrefix: 'my-custom-hash',
namedExport: true,
@@ -1089,6 +1089,56 @@ module.exports = {
};
```
+### `namedExport`
+
+Type: `Boolean`
+Default: `false`
+
+Enable/disable ES modules named export for css classes.
+Names of exported classes are converted to camelCase.
+
+**styles.css**
+
+```css
+.foo-baz {
+ color: red;
+}
+.bar {
+ color: blue;
+}
+```
+
+**index.js**
+
+```js
+import { fooBaz, bar } from './styles.css';
+
+console.log(fooBaz, bar);
+```
+
+You can enable a ES module named export using:
+
+**webpack.config.js**
+
+```js
+module.exports = {
+ module: {
+ rules: [
+ {
+ test: /\.css$/i,
+ loader: 'css-loader',
+ options: {
+ esModule: true,
+ modules: {
+ namedExport: true,
+ },
+ },
+ },
+ ],
+ },
+};
+```
+
## Examples
### Assets
From 2b590463442d1ee3fc57b22e6db6d870188036fd Mon Sep 17 00:00:00 2001
From: cap-Bernardito
Date: Thu, 16 Jul 2020 13:51:58 +0300
Subject: [PATCH 2/9] feat: namedExport
---
README.md | 52 +---------------------------------------------------
1 file changed, 1 insertion(+), 51 deletions(-)
diff --git a/README.md b/README.md
index b344a523..94b64786 100644
--- a/README.md
+++ b/README.md
@@ -118,7 +118,6 @@ module.exports = {
| **[`importLoaders`](#importloaders)** | `{Number}` | `0` | Enables/Disables or setups number of loaders applied before CSS loader |
| **[`onlyLocals`](#onlylocals)** | `{Boolean}` | `false` | Export only locals |
| **[`esModule`](#esmodule)** | `{Boolean}` | `false` | Use ES modules syntax |
-| **[`namedExport`](#namedExport)** | `{Boolean}` | `false` | Use ES modules named export |
### `url`
@@ -532,6 +531,7 @@ module.exports = {
mode: 'local',
exportGlobals: true,
localIdentName: '[path][name]__[local]--[hash:base64:5]',
+ localsConvention: 'camelCase',
context: path.resolve(__dirname, 'src'),
hashPrefix: 'my-custom-hash',
namedExport: true,
@@ -1089,56 +1089,6 @@ module.exports = {
};
```
-### `namedExport`
-
-Type: `Boolean`
-Default: `false`
-
-Enable/disable ES modules named export for css classes.
-Names of exported classes are converted to camelCase.
-
-**styles.css**
-
-```css
-.foo-baz {
- color: red;
-}
-.bar {
- color: blue;
-}
-```
-
-**index.js**
-
-```js
-import { fooBaz, bar } from './styles.css';
-
-console.log(fooBaz, bar);
-```
-
-You can enable a ES module named export using:
-
-**webpack.config.js**
-
-```js
-module.exports = {
- module: {
- rules: [
- {
- test: /\.css$/i,
- loader: 'css-loader',
- options: {
- esModule: true,
- modules: {
- namedExport: true,
- },
- },
- },
- ],
- },
-};
-```
-
## Examples
### Assets
From 99cfb336569c191629292156aa4e5ec87e2b42ce Mon Sep 17 00:00:00 2001
From: cap-Bernardito
Date: Thu, 16 Jul 2020 14:35:07 +0300
Subject: [PATCH 3/9] refactor: enable esModules by default
---
README.md | 6 +-
package-lock.json | 98 +++++++++++++++++
package.json | 3 +
test/__snapshots__/loader.test.js.snap | 140 +++++++++++++++++++++++++
test/fixtures/simple-style.js | 2 +
test/helpers/index.js | 2 +
test/helpers/runInJsDom.js | 44 ++++++++
test/loader.test.js | 138 ++++++++++++++++++++++++
8 files changed, 430 insertions(+), 3 deletions(-)
create mode 100644 test/fixtures/simple-style.js
create mode 100644 test/helpers/runInJsDom.js
diff --git a/README.md b/README.md
index 94b64786..7d7eb1a2 100644
--- a/README.md
+++ b/README.md
@@ -1066,10 +1066,10 @@ module.exports = {
Type: `Boolean`
Default: `false`
-By default, `css-loader` generates JS modules that use the CommonJS modules syntax.
+By default, `css-loader` generates JS modules that use the ES 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:
+You can enable a CommonJS modules syntax using:
**webpack.config.js**
@@ -1081,7 +1081,7 @@ module.exports = {
test: /\.css$/i,
loader: 'css-loader',
options: {
- esModule: true,
+ esModule: false,
},
},
],
diff --git a/package-lock.json b/package-lock.json
index 25342f55..ec6b4671 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -10746,6 +10746,51 @@
"integrity": "sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==",
"dev": true
},
+ "mini-css-extract-plugin": {
+ "version": "0.9.0",
+ "resolved": "https://registry.npmjs.org/mini-css-extract-plugin/-/mini-css-extract-plugin-0.9.0.tgz",
+ "integrity": "sha512-lp3GeY7ygcgAmVIcRPBVhIkf8Us7FZjA+ILpal44qLdSu11wmjKQ3d9k15lfD7pO4esu9eUIAW7qiYIBppv40A==",
+ "dev": true,
+ "requires": {
+ "loader-utils": "^1.1.0",
+ "normalize-url": "1.9.1",
+ "schema-utils": "^1.0.0",
+ "webpack-sources": "^1.1.0"
+ },
+ "dependencies": {
+ "json5": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz",
+ "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==",
+ "dev": true,
+ "requires": {
+ "minimist": "^1.2.0"
+ }
+ },
+ "loader-utils": {
+ "version": "1.4.0",
+ "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.4.0.tgz",
+ "integrity": "sha512-qH0WSMBtn/oHuwjy/NucEgbx5dbxxnxup9s4PVXJUDHZBQY+s0NWA9rJf53RBnQZxfch7euUui7hpoAPvALZdA==",
+ "dev": true,
+ "requires": {
+ "big.js": "^5.2.2",
+ "emojis-list": "^3.0.0",
+ "json5": "^1.0.1"
+ }
+ },
+ "schema-utils": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-1.0.0.tgz",
+ "integrity": "sha512-i27Mic4KovM/lnGsy8whRCHhc7VicJajAjTrYg11K9zfZXnYIt4k5F+kZkwjnrhKzLic/HLU4j11mjsz2G/75g==",
+ "dev": true,
+ "requires": {
+ "ajv": "^6.1.0",
+ "ajv-errors": "^1.0.0",
+ "ajv-keywords": "^3.1.0"
+ }
+ }
+ }
+ },
"minimalistic-assert": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz",
@@ -11120,6 +11165,18 @@
"integrity": "sha1-LRDAa9/TEuqXd2laTShDlFa3WUI=",
"dev": true
},
+ "normalize-url": {
+ "version": "1.9.1",
+ "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-1.9.1.tgz",
+ "integrity": "sha1-LMDWazHqIwNkWENuNiDYWVTGbDw=",
+ "dev": true,
+ "requires": {
+ "object-assign": "^4.0.1",
+ "prepend-http": "^1.0.0",
+ "query-string": "^4.1.0",
+ "sort-keys": "^1.0.0"
+ }
+ },
"npm-run-all": {
"version": "4.1.5",
"resolved": "https://registry.npmjs.org/npm-run-all/-/npm-run-all-4.1.5.tgz",
@@ -12245,6 +12302,12 @@
"integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==",
"dev": true
},
+ "prepend-http": {
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-1.0.4.tgz",
+ "integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=",
+ "dev": true
+ },
"prettier": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.0.5.tgz",
@@ -12447,6 +12510,16 @@
"integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==",
"dev": true
},
+ "query-string": {
+ "version": "4.3.4",
+ "resolved": "https://registry.npmjs.org/query-string/-/query-string-4.3.4.tgz",
+ "integrity": "sha1-u7aTucqRXCMlFbIosaArYJBD2+s=",
+ "dev": true,
+ "requires": {
+ "object-assign": "^4.1.0",
+ "strict-uri-encode": "^1.0.0"
+ }
+ },
"querystring": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz",
@@ -13272,6 +13345,15 @@
}
}
},
+ "sort-keys": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/sort-keys/-/sort-keys-1.1.2.tgz",
+ "integrity": "sha1-RBttTTRnmPG05J6JIK37oOVD+a0=",
+ "dev": true,
+ "requires": {
+ "is-plain-obj": "^1.0.0"
+ }
+ },
"source-list-map": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/source-list-map/-/source-list-map-2.0.1.tgz",
@@ -13560,6 +13642,12 @@
"integrity": "sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ==",
"dev": true
},
+ "strict-uri-encode": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz",
+ "integrity": "sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=",
+ "dev": true
+ },
"string-argv": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/string-argv/-/string-argv-0.3.1.tgz",
@@ -13709,6 +13797,16 @@
"integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=",
"dev": true
},
+ "style-loader": {
+ "version": "1.2.1",
+ "resolved": "https://registry.npmjs.org/style-loader/-/style-loader-1.2.1.tgz",
+ "integrity": "sha512-ByHSTQvHLkWE9Ir5+lGbVOXhxX10fbprhLvdg96wedFZb4NDekDPxVKv5Fwmio+QcMlkkNfuK+5W1peQ5CUhZg==",
+ "dev": true,
+ "requires": {
+ "loader-utils": "^2.0.0",
+ "schema-utils": "^2.6.6"
+ }
+ },
"supports-color": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz",
diff --git a/package.json b/package.json
index 1b6b4d61..312847cc 100644
--- a/package.json
+++ b/package.json
@@ -76,8 +76,10 @@
"file-loader": "^6.0.0",
"husky": "^4.2.5",
"jest": "^26.1.0",
+ "jsdom": "^16.3.0",
"lint-staged": "^10.2.11",
"memfs": "^3.2.0",
+ "mini-css-extract-plugin": "^0.9.0",
"npm-run-all": "^4.1.5",
"postcss-loader": "^3.0.0",
"postcss-preset-env": "^6.7.0",
@@ -86,6 +88,7 @@
"sass-loader": "^9.0.2",
"standard-version": "^8.0.2",
"strip-ansi": "^6.0.0",
+ "style-loader": "^1.2.1",
"url-loader": "^4.1.0",
"webpack": "^4.43.0"
},
diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap
index 8f6ee1cd..eabfc17c 100644
--- a/test/__snapshots__/loader.test.js.snap
+++ b/test/__snapshots__/loader.test.js.snap
@@ -381,6 +381,76 @@ exports[`loader should work with ModuleConcatenationPlugin: errors 1`] = `Array
exports[`loader should work with ModuleConcatenationPlugin: warnings 1`] = `Array []`;
+exports[`loader should work with commonjs-css-loader + commonjs-mini-css-extract-plugin: css 1`] = `
+".some-class {
+ color: red;
+}
+
+"
+`;
+
+exports[`loader should work with commonjs-css-loader + commonjs-mini-css-extract-plugin: errors 1`] = `Array []`;
+
+exports[`loader should work with commonjs-css-loader + commonjs-mini-css-extract-plugin: result 1`] = `Object {}`;
+
+exports[`loader should work with commonjs-css-loader + commonjs-mini-css-extract-plugin: warnings 1`] = `Array []`;
+
+exports[`loader should work with commonjs-css-loader + commonjs-style-loader: DOM 1`] = `
+"
+ style-loader test
+
+
+
+ Body
+
+