css-loader 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  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.
4
4
 
5
+ ## [3.1.0](https://github.com/webpack-contrib/css-loader/compare/v3.0.0...v3.1.0) (2019-07-18)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * converting all (including reserved and control) filesystem characters to `-` (it was regression in `3.0.0` version) ([#972](https://github.com/webpack-contrib/css-loader/issues/972)) ([f51859b](https://github.com/webpack-contrib/css-loader/commit/f51859b))
11
+ * default context should be undefined instead of null ([#965](https://github.com/webpack-contrib/css-loader/issues/965)) ([9c32885](https://github.com/webpack-contrib/css-loader/commit/9c32885))
12
+
13
+
14
+ ### Features
15
+
16
+ * allow `modules.getLocalIdent` to return a falsy value ([#963](https://github.com/webpack-contrib/css-loader/issues/963)) ([9c3571c](https://github.com/webpack-contrib/css-loader/commit/9c3571c))
17
+ * improved validation error messages ([65e4fc0](https://github.com/webpack-contrib/css-loader/commit/65e4fc0))
18
+
19
+
20
+
5
21
  ## [3.0.0](https://github.com/webpack-contrib/css-loader/compare/v2.1.1...v3.0.0) (2019-06-11)
6
22
 
7
23
 
package/README.md CHANGED
@@ -109,21 +109,22 @@ module.exports = {
109
109
 
110
110
  ## Options
111
111
 
112
- | Name | Type | Default | Description |
113
- | :-----------------------------------------: | :-------------------------: | :-----: | :------------------------------------------------- |
114
- | **[`url`](#url)** | `{Boolean\|Function}` | `true` | Enable/Disable `url()` handling |
115
- | **[`import`](#import)** | `{Boolean\|Function}` | `true` | Enable/Disable @import handling |
116
- | **[`modules`](#modules)** | `{Boolean\|String\|Object}` | `false` | Enable/Disable CSS Modules and setup their options |
117
- | **[`sourceMap`](#sourcemap)** | `{Boolean}` | `false` | Enable/Disable Sourcemaps |
118
- | **[`importLoaders`](#importloaders)** | `{Number}` | `0` | Number of loaders applied before CSS loader |
119
- | **[`localsConvention`](#localsconvention)** | `{String}` | `asIs` | Setup style of exported classnames |
120
- | **[`onlyLocals`](#onlylocals)** | `{Boolean}` | `false` | Export only locals |
112
+ | Name | Type | Default | Description |
113
+ | :-----------------------------------------: | :-------------------------: | :-----: | :--------------------------------------------------------------------- |
114
+ | **[`url`](#url)** | `{Boolean\|Function}` | `true` | Enables/Disables `url`/`image-set` functions handling |
115
+ | **[`import`](#import)** | `{Boolean\|Function}` | `true` | Enables/Disables `@import` at-rules handling |
116
+ | **[`modules`](#modules)** | `{Boolean\|String\|Object}` | `false` | Enables/Disables CSS Modules and their configuration |
117
+ | **[`sourceMap`](#sourcemap)** | `{Boolean}` | `false` | Enables/Disables generation of source maps |
118
+ | **[`importLoaders`](#importloaders)** | `{Number}` | `0` | Enables/Disables or setups number of loaders applied before CSS loader |
119
+ | **[`localsConvention`](#localsconvention)** | `{String}` | `asIs` | Style of exported classnames |
120
+ | **[`onlyLocals`](#onlylocals)** | `{Boolean}` | `false` | Export only locals |
121
121
 
122
122
  ### `url`
123
123
 
124
124
  Type: `Boolean|Function`
125
125
  Default: `true`
126
126
 
127
+ Enables/Disables `url`/`image-set` functions handling.
127
128
  Control `url()` resolving. Absolute URLs and root-relative URLs are not resolving.
128
129
 
129
130
  Examples resolutions:
@@ -203,6 +204,7 @@ module.exports = {
203
204
  Type: `Boolean`
204
205
  Default: `true`
205
206
 
207
+ Enables/Disables `@import` at-rules handling.
206
208
  Control `@import` resolving. Absolute urls in `@import` will be moved in runtime code.
207
209
 
208
210
  Examples resolutions:
@@ -285,6 +287,8 @@ module.exports = {
285
287
  Type: `Boolean|String|Object`
286
288
  Default: `false`
287
289
 
290
+ Enables/Disables CSS Modules and their configuration.
291
+
288
292
  The `modules` option enables/disables the **[CSS Modules](https://github.com/css-modules/css-modules)** specification and setup basic behaviour.
289
293
 
290
294
  Using `false` value increase performance because we avoid parsing **CSS Modules** features, it will be useful for developers who use vanilla css or use other technologies.
@@ -568,6 +572,15 @@ Default: `[hash:base64]`
568
572
  You can configure the generated ident with the `localIdentName` query parameter.
569
573
  See [loader-utils's documentation](https://github.com/webpack/loader-utils#interpolatename) for more information on options.
570
574
 
575
+ Recommendations:
576
+
577
+ - use `[path][name]__[local]` for development
578
+ - use `[hash:base64]` for production
579
+
580
+ The `[local]` placeholder contains original class.
581
+
582
+ **Note:** all reserved (`<>:"/\|?*`) and control filesystem characters (excluding characters in the `[local]` placeholder) will be converted to `-`.
583
+
571
584
  **webpack.config.js**
572
585
 
573
586
  ```js
@@ -703,14 +716,12 @@ module.exports = {
703
716
  Type: `Boolean`
704
717
  Default: `false`
705
718
 
706
- To include source maps set the `sourceMap` option.
719
+ Enables/Disables generation of source maps.
707
720
 
708
- I.e. the `mini-css-extract-plugin` can handle them.
721
+ To include source maps set the `sourceMap` option.
709
722
 
710
723
  They are not enabled by default because they expose a runtime overhead and increase in bundle size (JS source maps do not).
711
724
 
712
- In addition to that relative paths are buggy and you need to use an absolute public path which includes the server URL.
713
-
714
725
  **webpack.config.js**
715
726
 
716
727
  ```js
@@ -734,6 +745,8 @@ module.exports = {
734
745
  Type: `Number`
735
746
  Default: `0`
736
747
 
748
+ Enables/Disables or setups number of loaders applied before CSS loader.
749
+
737
750
  The option `importLoaders` allows you to configure how many loaders before `css-loader` should be applied to `@import`ed resources.
738
751
 
739
752
  **webpack.config.js**
@@ -749,7 +762,10 @@ module.exports = {
749
762
  {
750
763
  loader: 'css-loader',
751
764
  options: {
752
- importLoaders: 2, // 0 => no loaders (default); 1 => postcss-loader; 2 => postcss-loader, sass-loader
765
+ importLoaders: 2,
766
+ // 0 => no loaders (default);
767
+ // 1 => postcss-loader;
768
+ // 2 => postcss-loader, sass-loader
753
769
  },
754
770
  },
755
771
  'postcss-loader',
@@ -768,6 +784,8 @@ This may change in the future when the module system (i. e. webpack) supports lo
768
784
  Type: `String`
769
785
  Default: `undefined`
770
786
 
787
+ Style of exported classnames.
788
+
771
789
  By default, the exported JSON keys mirror the class names (i.e `asIs` value).
772
790
 
773
791
  | Name | Type | Description |
@@ -814,7 +832,9 @@ module.exports = {
814
832
  Type: `Boolean`
815
833
  Default: `false`
816
834
 
817
- Export only locals (**useful** when you use **css modules**).
835
+ Export only locals.
836
+
837
+ **Useful** when you use **css modules** for pre-rendering (for example SSR).
818
838
  For pre-rendering with `mini-css-extract-plugin` you should use this option instead of `style-loader!css-loader` **in the pre-rendering bundle**.
819
839
  It doesn't embed CSS but only exports the identifier mappings.
820
840
 
package/dist/index.js CHANGED
@@ -31,7 +31,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
31
31
  */
32
32
  function loader(content, map, meta) {
33
33
  const options = (0, _loaderUtils.getOptions)(this) || {};
34
- (0, _schemaUtils.default)(_options.default, options, 'CSS Loader');
34
+ (0, _schemaUtils.default)(_options.default, options, {
35
+ name: 'CSS Loader',
36
+ baseDataPath: 'options'
37
+ });
35
38
  const callback = this.async();
36
39
  const sourceMap = options.sourceMap || false; // Some loaders (example `"postcss-loader": "1.x.x"`) always generates source map, we should remove it
37
40
  // eslint-disable-next-line no-param-reassign
package/dist/options.json CHANGED
@@ -2,6 +2,7 @@
2
2
  "additionalProperties": false,
3
3
  "properties": {
4
4
  "url": {
5
+ "description": "Enables/Disables 'url'/'image-set' functions handling (https://github.com/webpack-contrib/css-loader#url).",
5
6
  "anyOf": [
6
7
  {
7
8
  "type": "boolean"
@@ -12,6 +13,7 @@
12
13
  ]
13
14
  },
14
15
  "import": {
16
+ "description": "Enables/Disables '@import' at-rules handling (https://github.com/webpack-contrib/css-loader#import).",
15
17
  "anyOf": [
16
18
  {
17
19
  "type": "boolean"
@@ -22,12 +24,12 @@
22
24
  ]
23
25
  },
24
26
  "modules": {
27
+ "description": "Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).",
25
28
  "anyOf": [
26
29
  {
27
30
  "type": "boolean"
28
31
  },
29
32
  {
30
- "type": "string",
31
33
  "enum": ["local", "global"]
32
34
  },
33
35
  {
@@ -35,7 +37,6 @@
35
37
  "additionalProperties": false,
36
38
  "properties": {
37
39
  "mode": {
38
- "type": "string",
39
40
  "enum": ["local", "global"]
40
41
  },
41
42
  "localIdentName": {
@@ -72,9 +73,11 @@
72
73
  ]
73
74
  },
74
75
  "sourceMap": {
76
+ "description": "Enables/Disables generation of source maps (https://github.com/webpack-contrib/css-loader#sourcemap).",
75
77
  "type": "boolean"
76
78
  },
77
79
  "importLoaders": {
80
+ "description": "Enables/Disables or setups number of loaders applied before CSS loader (https://github.com/webpack-contrib/css-loader#importloaders).",
78
81
  "anyOf": [
79
82
  {
80
83
  "type": "boolean"
@@ -85,14 +88,11 @@
85
88
  ]
86
89
  },
87
90
  "localsConvention": {
88
- "anyOf": [
89
- {
90
- "type": "string",
91
- "enum": ["asIs", "camelCase", "camelCaseOnly", "dashes", "dashesOnly"]
92
- }
93
- ]
91
+ "description": "Style of exported classnames (https://github.com/webpack-contrib/css-loader#localsconvention).",
92
+ "enum": ["asIs", "camelCase", "camelCaseOnly", "dashes", "dashesOnly"]
94
93
  },
95
94
  "onlyLocals": {
95
+ "description": "Export only locals (https://github.com/webpack-contrib/css-loader#onlylocals).",
96
96
  "type": "boolean"
97
97
  }
98
98
  },
package/dist/utils.js CHANGED
@@ -86,7 +86,13 @@ function unescape(str) {
86
86
  String.fromCharCode(high >> 10 | 0xd800, high & 0x3ff | 0xdc00);
87
87
  /* eslint-enable line-comment-position */
88
88
  });
89
- }
89
+ } // eslint-disable-next-line no-control-regex
90
+
91
+
92
+ const filenameReservedRegex = /[<>:"/\\|?*\x00-\x1F]/g; // eslint-disable-next-line no-control-regex
93
+
94
+ const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g;
95
+ const reRelativePath = /^\.+/;
90
96
 
91
97
  function getLocalIdent(loaderContext, localIdentName, localName, options) {
92
98
  if (!options.context) {
@@ -100,7 +106,7 @@ function getLocalIdent(loaderContext, localIdentName, localName, options) {
100
106
  // Also directories can contains invalid characters for css we need escape their too
101
107
 
102
108
  return (0, _cssesc.default)(_loaderUtils.default.interpolateName(loaderContext, localIdentName, options) // For `[hash]` placeholder
103
- .replace(/^((-?[0-9])|--)/, '_$1'), {
109
+ .replace(/^((-?[0-9])|--)/, '_$1').replace(filenameReservedRegex, '-').replace(reControlChars, '-').replace(reRelativePath, '-'), {
104
110
  isIdentifier: true
105
111
  }).replace(/\\\[local\\\]/gi, localName);
106
112
  }
@@ -124,7 +130,6 @@ function getModulesPlugins(options, loaderContext) {
124
130
  mode: 'local',
125
131
  localIdentName: '[hash:base64]',
126
132
  getLocalIdent,
127
- context: null,
128
133
  hashPrefix: '',
129
134
  localIdentRegExp: null
130
135
  };
@@ -139,11 +144,21 @@ function getModulesPlugins(options, loaderContext) {
139
144
  mode: modulesOptions.mode
140
145
  }), (0, _postcssModulesExtractImports.default)(), (0, _postcssModulesScope.default)({
141
146
  generateScopedName: function generateScopedName(exportName) {
142
- return modulesOptions.getLocalIdent(loaderContext, modulesOptions.localIdentName, exportName, {
147
+ let localIdent = modulesOptions.getLocalIdent(loaderContext, modulesOptions.localIdentName, exportName, {
143
148
  context: modulesOptions.context,
144
149
  hashPrefix: modulesOptions.hashPrefix,
145
150
  regExp: modulesOptions.localIdentRegExp
146
151
  });
152
+
153
+ if (!localIdent) {
154
+ localIdent = getLocalIdent(loaderContext, modulesOptions.localIdentName, exportName, {
155
+ context: modulesOptions.context,
156
+ hashPrefix: modulesOptions.hashPrefix,
157
+ regExp: modulesOptions.localIdentRegExp
158
+ });
159
+ }
160
+
161
+ return localIdent;
147
162
  }
148
163
  })];
149
164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-loader",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "css loader module for webpack",
5
5
  "license": "MIT",
6
6
  "repository": "webpack-contrib/css-loader",
@@ -52,40 +52,40 @@
52
52
  "postcss-modules-scope": "^2.1.0",
53
53
  "postcss-modules-values": "^3.0.0",
54
54
  "postcss-value-parser": "^4.0.0",
55
- "schema-utils": "^1.0.0"
55
+ "schema-utils": "^2.0.0"
56
56
  },
57
57
  "devDependencies": {
58
- "@babel/cli": "^7.4.4",
59
- "@babel/core": "^7.4.5",
60
- "@babel/preset-env": "^7.4.5",
61
- "@commitlint/cli": "^8.0.0",
62
- "@commitlint/config-conventional": "^8.0.0",
63
- "@webpack-contrib/defaults": "^5.0.0",
58
+ "@babel/cli": "^7.5.0",
59
+ "@babel/core": "^7.5.4",
60
+ "@babel/preset-env": "^7.5.4",
61
+ "@commitlint/cli": "^8.1.0",
62
+ "@commitlint/config-conventional": "^8.1.0",
63
+ "@webpack-contrib/defaults": "^5.0.2",
64
64
  "@webpack-contrib/eslint-config-webpack": "^3.0.0",
65
65
  "babel-jest": "^24.8.0",
66
66
  "commitlint-azure-pipelines-cli": "^1.0.2",
67
67
  "cross-env": "^5.2.0",
68
- "del": "^4.1.1",
68
+ "del": "^5.0.0",
69
69
  "del-cli": "^2.0.0",
70
70
  "es-check": "^5.0.0",
71
71
  "eslint": "^5.16.0",
72
- "eslint-config-prettier": "^4.3.0",
73
- "eslint-plugin-import": "^2.17.3",
72
+ "eslint-config-prettier": "^6.0.0",
73
+ "eslint-plugin-import": "^2.18.0",
74
74
  "file-loader": "^4.0.0",
75
- "husky": "^2.4.0",
75
+ "husky": "^3.0.0",
76
76
  "jest": "^24.8.0",
77
77
  "jest-junit": "^6.4.0",
78
- "lint-staged": "^8.2.0",
78
+ "lint-staged": "^9.2.0",
79
79
  "memory-fs": "^0.4.1",
80
80
  "npm-run-all": "^4.1.5",
81
81
  "postcss-loader": "^3.0.0",
82
- "postcss-preset-env": "^6.6.0",
82
+ "postcss-preset-env": "^6.7.0",
83
83
  "prettier": "^1.18.2",
84
- "sass": "^1.21.0",
84
+ "sass": "^1.22.5",
85
85
  "sass-loader": "^7.1.0",
86
86
  "standard-version": "^6.0.1",
87
87
  "strip-ansi": "^5.2.0",
88
- "webpack": "^4.33.0"
88
+ "webpack": "^4.35.0"
89
89
  },
90
90
  "keywords": [
91
91
  "webpack",