css-loader 4.0.0 → 4.2.1

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,41 @@
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
+ ### [4.2.1](https://github.com/webpack-contrib/css-loader/compare/v4.2.0...v4.2.1) (2020-08-06)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * regression with the `exportOnlyLocals` option, now `locals` are not exported under the `locals` name, it was big regression, we apologize for that ([24c0a12](https://github.com/webpack-contrib/css-loader/commit/24c0a122d1396c08326a24f6184f5da09cf52ccc))
11
+
12
+ ## [4.2.0](https://github.com/webpack-contrib/css-loader/compare/v4.1.1...v4.2.0) (2020-07-31)
13
+
14
+
15
+ ### Features
16
+
17
+ * add `module.type` option, the `icss` option is deprecated ([#1150](https://github.com/webpack-contrib/css-loader/issues/1150)) ([68f72af](https://github.com/webpack-contrib/css-loader/commit/68f72af2a09111f74dcacbf7af019fe7eb40cb6c))
18
+
19
+ ### [4.1.1](https://github.com/webpack-contrib/css-loader/compare/v4.1.0...v4.1.1) (2020-07-30)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * remove unnecessary `console` call ([#1148](https://github.com/webpack-contrib/css-loader/issues/1148)) ([b1b90ca](https://github.com/webpack-contrib/css-loader/commit/b1b90caaea8eb045177749729340c7906454a84b))
25
+
26
+ ## [4.1.0](https://github.com/webpack-contrib/css-loader/compare/v4.0.0...v4.1.0) (2020-07-29)
27
+
28
+
29
+ ### Features
30
+
31
+ * add `icss` option ([#1140](https://github.com/webpack-contrib/css-loader/issues/1140)) ([a8ec7da](https://github.com/webpack-contrib/css-loader/commit/a8ec7da42234e0b2eb061d2a920669940bcbdf05))
32
+ * support absolute paths ([f9ba0ce](https://github.com/webpack-contrib/css-loader/commit/f9ba0ce11789770c4c9220478e9c98dbd432a5d6))
33
+
34
+
35
+ ### Bug Fixes
36
+
37
+ * do not crash with `data` URLs ([#1142](https://github.com/webpack-contrib/css-loader/issues/1142)) ([91bc64b](https://github.com/webpack-contrib/css-loader/commit/91bc64b81abfeffd174639a8fdf2366412c11426))
38
+ * performance ([#1144](https://github.com/webpack-contrib/css-loader/issues/1144)) ([4f1baa2](https://github.com/webpack-contrib/css-loader/commit/4f1baa211eb27b0b281ba9f262fa12e8aaefc0ba))
39
+
5
40
  ## [4.0.0](https://github.com/webpack-contrib/css-loader/compare/v3.6.0...v4.0.0) (2020-07-25)
6
41
 
7
42
 
@@ -19,7 +54,7 @@ All notable changes to this project will be documented in this file. See [standa
19
54
  * the `localsConvention` option was moved and renamed to the `modules.exportLocalsConvention` option
20
55
  * the `getLocalIndent` option should be always `Function` and should always return `String` value
21
56
  * the `onlyLocals` option was moved and renamed to the `modules.exportOnlyLocals` option
22
- * function arguments of the `import` option were changed, it is now `funciton(url, media, resourcePath) {}`
57
+ * function arguments of the `import` option were changed, it is now `function(url, media, resourcePath) {}`
23
58
  * inline syntax was changed, please write `~` before the file request, i.e. rewrite `url(~!!loader!package/img.png)` to `url(!!loader!~package/img.png)`
24
59
 
25
60
 
package/README.md CHANGED
@@ -113,10 +113,10 @@ module.exports = {
113
113
  | :-----------------------------------: | :-------------------------: | :----------------: | :--------------------------------------------------------------------- |
114
114
  | **[`url`](#url)** | `{Boolean\|Function}` | `true` | Enables/Disables `url`/`image-set` functions handling |
115
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 |
116
+ | **[`modules`](#modules)** | `{Boolean\|String\|Object}` | `{auto: true}` | Enables/Disables CSS Modules and their configuration |
117
117
  | **[`sourceMap`](#sourcemap)** | `{Boolean}` | `compiler.devtool` | Enables/Disables generation of source maps |
118
118
  | **[`importLoaders`](#importloaders)** | `{Number}` | `0` | Enables/Disables or setups number of loaders applied before CSS loader |
119
- | **[`esModule`](#esmodule)** | `{Boolean}` | `false` | Use ES modules syntax |
119
+ | **[`esModule`](#esmodule)** | `{Boolean}` | `true` | Use ES modules syntax |
120
120
 
121
121
  ### `url`
122
122
 
@@ -525,6 +525,7 @@ module.exports = {
525
525
  loader: 'css-loader',
526
526
  options: {
527
527
  modules: {
528
+ compileType: 'module',
528
529
  mode: 'local',
529
530
  auto: true,
530
531
  exportGlobals: true,
@@ -542,6 +543,38 @@ module.exports = {
542
543
  };
543
544
  ```
544
545
 
546
+ ##### `compileType`
547
+
548
+ Type: `'module' | 'icss'`
549
+ Default: `'module'`
550
+
551
+ Controls the level of compilation applied to the input styles.
552
+
553
+ The `module` handles `class` and `id` scoping and `@value` values.
554
+ The `icss` will only compile the low level `Interoperable CSS` format for declaring `:import` and `:export` dependencies between CSS and other languages.
555
+
556
+ ICSS underpins CSS Module support, and provides a low level syntax for other tools to implement CSS-module variations of their own.
557
+
558
+ **webpack.config.js**
559
+
560
+ ```js
561
+ module.exports = {
562
+ module: {
563
+ rules: [
564
+ {
565
+ test: /\.css$/i,
566
+ loader: 'css-loader',
567
+ options: {
568
+ modules: {
569
+ compileType: 'icss',
570
+ },
571
+ },
572
+ },
573
+ ],
574
+ },
575
+ };
576
+ ```
577
+
545
578
  ##### `auto`
546
579
 
547
580
  Type: `Boolean|RegExp|Function`
package/dist/index.js CHANGED
@@ -50,9 +50,8 @@ async function loader(content, map, meta) {
50
50
 
51
51
  const replacements = [];
52
52
  const exports = [];
53
- const needUseModulesPlugins = (0, _utils.shouldUseModulesPlugins)(options);
54
53
 
55
- if (needUseModulesPlugins) {
54
+ if ((0, _utils.shouldUseModulesPlugins)(options)) {
56
55
  plugins.push(...(0, _utils.getModulesPlugins)(options, this));
57
56
  }
58
57
 
@@ -61,11 +60,11 @@ async function loader(content, map, meta) {
61
60
 
62
61
  if ((0, _utils.shouldUseImportPlugin)(options)) {
63
62
  const resolver = this.getResolve({
63
+ conditionNames: ['style'],
64
+ extensions: ['.css'],
64
65
  mainFields: ['css', 'style', 'main', '...'],
65
66
  mainFiles: ['index', '...'],
66
- extensions: ['.css'],
67
- restrictions: [/\.css$/i],
68
- conditionNames: ['style']
67
+ restrictions: [/\.css$/i]
69
68
  });
70
69
  plugins.push((0, _plugins.importParser)({
71
70
  imports: importPluginImports,
@@ -82,8 +81,9 @@ async function loader(content, map, meta) {
82
81
 
83
82
  if ((0, _utils.shouldUseURLPlugin)(options)) {
84
83
  const urlResolver = this.getResolve({
85
- mainFields: ['asset'],
86
84
  conditionNames: ['asset'],
85
+ mainFields: ['asset'],
86
+ mainFiles: [],
87
87
  extensions: []
88
88
  });
89
89
  plugins.push((0, _plugins.urlParser)({
@@ -100,12 +100,12 @@ async function loader(content, map, meta) {
100
100
  const icssPluginImports = [];
101
101
  const icssPluginApi = [];
102
102
 
103
- if (needUseModulesPlugins) {
103
+ if ((0, _utils.shouldUseIcssPlugin)(options)) {
104
104
  const icssResolver = this.getResolve({
105
- mainFields: ['css', 'style', 'main', '...'],
106
- mainFiles: ['index', '...'],
105
+ conditionNames: ['style'],
107
106
  extensions: [],
108
- conditionNames: ['style']
107
+ mainFields: ['css', 'style', 'main', '...'],
108
+ mainFiles: ['index', '...']
109
109
  });
110
110
  plugins.push((0, _plugins.icssParser)({
111
111
  imports: icssPluginImports,
package/dist/options.json CHANGED
@@ -36,6 +36,10 @@
36
36
  "type": "object",
37
37
  "additionalProperties": false,
38
38
  "properties": {
39
+ "compileType": {
40
+ "description": "Controls the extent to which css-loader will process module code (https://github.com/webpack-contrib/css-loader#type)",
41
+ "enum": ["module", "icss"]
42
+ },
39
43
  "auto": {
40
44
  "description": "Allows auto enable CSS modules based on filename (https://github.com/webpack-contrib/css-loader#auto).",
41
45
  "anyOf": [
@@ -118,6 +122,10 @@
118
122
  }
119
123
  ]
120
124
  },
125
+ "icss": {
126
+ "description": "Enables/Disables handling the CSS module interoperable import/export format ((https://github.com/webpack-contrib/css-loader#icss)",
127
+ "type": "boolean"
128
+ },
121
129
  "sourceMap": {
122
130
  "description": "Enables/Disables generation of source maps (https://github.com/webpack-contrib/css-loader#sourcemap).",
123
131
  "type": "boolean"
@@ -103,16 +103,16 @@ var _default = _postcss.default.plugin(pluginName, options => async (css, result
103
103
  } = parsedResult;
104
104
  let normalizedUrl = url;
105
105
  let prefix = '';
106
- const queryParts = normalizedUrl.split('!');
107
-
108
- if (queryParts.length > 1) {
109
- normalizedUrl = queryParts.pop();
110
- prefix = queryParts.join('!');
111
- }
112
-
113
106
  const isRequestable = (0, _utils.isUrlRequestable)(normalizedUrl);
114
107
 
115
108
  if (isRequestable) {
109
+ const queryParts = normalizedUrl.split('!');
110
+
111
+ if (queryParts.length > 1) {
112
+ normalizedUrl = queryParts.pop();
113
+ prefix = queryParts.join('!');
114
+ }
115
+
116
116
  normalizedUrl = (0, _utils.normalizeUrl)(normalizedUrl, isStringValue); // Empty url after normalize - `@import '\
117
117
  // \
118
118
  // \
@@ -142,8 +142,7 @@ var _default = _postcss.default.plugin(pluginName, options => async (css, result
142
142
 
143
143
  if (isRequestable) {
144
144
  const request = (0, _utils.requestify)(normalizedUrl, options.rootContext);
145
-
146
- const doResolve = async () => {
145
+ tasks.push((async () => {
147
146
  const {
148
147
  resolver,
149
148
  context
@@ -155,9 +154,7 @@ var _default = _postcss.default.plugin(pluginName, options => async (css, result
155
154
  prefix,
156
155
  isRequestable
157
156
  };
158
- };
159
-
160
- tasks.push(doResolve());
157
+ })());
161
158
  } else {
162
159
  tasks.push({
163
160
  url,
@@ -33,6 +33,10 @@ function shouldHandleRule(rule, decl, result) {
33
33
  return false;
34
34
  }
35
35
 
36
+ if (!(0, _utils.isUrlRequestable)(rule.url)) {
37
+ return false;
38
+ }
39
+
36
40
  return true;
37
41
  }
38
42
 
@@ -157,11 +161,6 @@ var _default = _postcss.default.plugin(pluginName, options => async (css, result
157
161
 
158
162
  normalizedUrl = (0, _utils.normalizeUrl)(normalizedUrl, isStringValue);
159
163
 
160
- if (!(0, _utils.isUrlRequestable)(normalizedUrl)) {
161
- // eslint-disable-next-line no-continue
162
- continue;
163
- }
164
-
165
164
  if (!options.filter(normalizedUrl)) {
166
165
  // eslint-disable-next-line no-continue
167
166
  continue;
@@ -181,8 +180,7 @@ var _default = _postcss.default.plugin(pluginName, options => async (css, result
181
180
  let hash = query ? '?' : '';
182
181
  hash += hashOrQuery ? `#${hashOrQuery}` : '';
183
182
  const request = (0, _utils.requestify)(pathname, options.rootContext);
184
-
185
- const doResolve = async () => {
183
+ tasks.push((async () => {
186
184
  const {
187
185
  resolver,
188
186
  context
@@ -194,9 +192,7 @@ var _default = _postcss.default.plugin(pluginName, options => async (css, result
194
192
  hash,
195
193
  parsedResult
196
194
  };
197
- };
198
-
199
- tasks.push(doResolve());
195
+ })());
200
196
  }
201
197
 
202
198
  const results = await Promise.all(tasks);
package/dist/utils.js CHANGED
@@ -7,6 +7,7 @@ exports.normalizeOptions = normalizeOptions;
7
7
  exports.shouldUseModulesPlugins = shouldUseModulesPlugins;
8
8
  exports.shouldUseImportPlugin = shouldUseImportPlugin;
9
9
  exports.shouldUseURLPlugin = shouldUseURLPlugin;
10
+ exports.shouldUseIcssPlugin = shouldUseIcssPlugin;
10
11
  exports.normalizeUrl = normalizeUrl;
11
12
  exports.requestify = requestify;
12
13
  exports.getFilter = getFilter;
@@ -98,6 +99,10 @@ function normalizeUrl(url, isStringValue) {
98
99
  normalizedUrl = normalizedUrl.replace(/\\[\n]/g, '');
99
100
  }
100
101
 
102
+ if (matchNativeWin32Path.test(url)) {
103
+ return decodeURIComponent(normalizedUrl);
104
+ }
105
+
101
106
  return decodeURIComponent(unescape(normalizedUrl));
102
107
  }
103
108
 
@@ -106,7 +111,7 @@ function requestify(url, rootContext) {
106
111
  return (0, _url.fileURLToPath)(url);
107
112
  }
108
113
 
109
- return mayBeServerRelativeUrl(url) ? (0, _loaderUtils.urlToRequest)(url, rootContext) : (0, _loaderUtils.urlToRequest)(url);
114
+ return url.charAt(0) === '/' ? (0, _loaderUtils.urlToRequest)(url, rootContext) : (0, _loaderUtils.urlToRequest)(url);
110
115
  }
111
116
 
112
117
  function getFilter(filter, resourcePath) {
@@ -137,6 +142,7 @@ function getModulesOptions(rawOptions, loaderContext) {
137
142
  }
138
143
 
139
144
  let modulesOptions = {
145
+ compileType: rawOptions.icss ? 'icss' : 'module',
140
146
  auto: true,
141
147
  mode: 'local',
142
148
  exportGlobals: false,
@@ -203,10 +209,17 @@ function getModulesOptions(rawOptions, loaderContext) {
203
209
  }
204
210
 
205
211
  function normalizeOptions(rawOptions, loaderContext) {
212
+ if (rawOptions.icss) {
213
+ loaderContext.emitWarning(new Error('The "icss" option is deprecated, use "modules.compileType: "icss"" instead'));
214
+ }
215
+
216
+ const modulesOptions = getModulesOptions(rawOptions, loaderContext);
206
217
  return {
207
218
  url: typeof rawOptions.url === 'undefined' ? true : rawOptions.url,
208
219
  import: typeof rawOptions.import === 'undefined' ? true : rawOptions.import,
209
- modules: getModulesOptions(rawOptions, loaderContext),
220
+ modules: modulesOptions,
221
+ // TODO remove in the next major release
222
+ icss: typeof rawOptions.icss === 'undefined' ? false : rawOptions.icss,
210
223
  sourceMap: typeof rawOptions.sourceMap === 'boolean' ? rawOptions.sourceMap : loaderContext.sourceMap,
211
224
  importLoaders: rawOptions.importLoaders,
212
225
  esModule: typeof rawOptions.esModule === 'undefined' ? true : rawOptions.esModule
@@ -238,7 +251,11 @@ function shouldUseURLPlugin(options) {
238
251
  }
239
252
 
240
253
  function shouldUseModulesPlugins(options) {
241
- return Boolean(options.modules);
254
+ return options.modules.compileType === 'module';
255
+ }
256
+
257
+ function shouldUseIcssPlugin(options) {
258
+ return options.icss === true || Boolean(options.modules);
242
259
  }
243
260
 
244
261
  function getModulesPlugins(options, loaderContext) {
@@ -328,7 +345,16 @@ function getImportCode(imports, options) {
328
345
  url,
329
346
  icss
330
347
  } = item;
331
- code += options.esModule ? icss && options.modules.namedExport ? `import ${importName}, * as ${importName}_NAMED___ from ${url};\n` : `import ${importName} from ${url};\n` : `var ${importName} = require(${url});\n`;
348
+
349
+ if (options.esModule) {
350
+ if (icss && options.modules.namedExport) {
351
+ code += `import ${options.modules.exportOnlyLocals ? '' : `${importName}, `}* as ${importName}_NAMED___ from ${url};\n`;
352
+ } else {
353
+ code += `import ${importName} from ${url};\n`;
354
+ }
355
+ } else {
356
+ code += `var ${importName} = require(${url});\n`;
357
+ }
332
358
  }
333
359
 
334
360
  return code ? `// Imports\n${code}` : '';
@@ -336,7 +362,7 @@ function getImportCode(imports, options) {
336
362
 
337
363
  function getModuleCode(result, api, replacements, options) {
338
364
  if (options.modules.exportOnlyLocals === true) {
339
- return 'var ___CSS_LOADER_EXPORT___ = {};\n';
365
+ return '';
340
366
  }
341
367
 
342
368
  const {
@@ -385,7 +411,7 @@ function dashesCamelCase(str) {
385
411
  }
386
412
 
387
413
  function getExportCode(exports, replacements, options) {
388
- let code = '';
414
+ let code = '// Exports\n';
389
415
  let localsCode = '';
390
416
 
391
417
  const addExportToLocalsCode = (name, value) => {
@@ -458,18 +484,31 @@ function getExportCode(exports, replacements, options) {
458
484
  const {
459
485
  importName
460
486
  } = item;
461
- localsCode = localsCode.replace(new RegExp(replacementName, 'g'), () => options.modules.namedExport ? `" + ${importName}_NAMED___[${JSON.stringify((0, _camelcase.default)(localName))}] + "` : `" + ${importName}.locals[${JSON.stringify(localName)}] + "`);
487
+ localsCode = localsCode.replace(new RegExp(replacementName, 'g'), () => {
488
+ if (options.modules.namedExport) {
489
+ return `" + ${importName}_NAMED___[${JSON.stringify((0, _camelcase.default)(localName))}] + "`;
490
+ } else if (options.modules.exportOnlyLocals) {
491
+ return `" + ${importName}[${JSON.stringify(localName)}] + "`;
492
+ }
493
+
494
+ return `" + ${importName}.locals[${JSON.stringify(localName)}] + "`;
495
+ });
462
496
  } else {
463
497
  localsCode = localsCode.replace(new RegExp(replacementName, 'g'), () => `" + ${replacementName} + "`);
464
498
  }
465
499
  }
466
500
 
501
+ if (options.modules.exportOnlyLocals) {
502
+ code += options.modules.namedExport ? localsCode : `${options.esModule ? 'export default' : 'module.exports ='} {\n${localsCode}\n};\n`;
503
+ return code;
504
+ }
505
+
467
506
  if (localsCode) {
468
- code += options.modules.namedExport ? `${localsCode}` : `___CSS_LOADER_EXPORT___.locals = {\n${localsCode}\n};\n`;
507
+ code += options.modules.namedExport ? localsCode : `___CSS_LOADER_EXPORT___.locals = {\n${localsCode}\n};\n`;
469
508
  }
470
509
 
471
510
  code += `${options.esModule ? 'export default' : 'module.exports ='} ___CSS_LOADER_EXPORT___;\n`;
472
- return `// Exports\n${code}`;
511
+ return code;
473
512
  }
474
513
 
475
514
  async function resolveRequests(resolve, context, possibleRequests) {
@@ -485,33 +524,29 @@ async function resolveRequests(resolve, context, possibleRequests) {
485
524
  return resolveRequests(resolve, context, tailPossibleRequests);
486
525
  });
487
526
  }
488
- /*
489
- * May be url is server-relative url, but not //example.com
490
- * */
527
+
528
+ function isUrlRequestable(url) {
529
+ // Protocol-relative URLs
530
+ if (/^\/\//.test(url)) {
531
+ return false;
532
+ } // `file:` protocol
491
533
 
492
534
 
493
- function mayBeServerRelativeUrl(url) {
494
- if (url.charAt(0) === '/' && !/^\/\//.test(url)) {
535
+ if (/^file:/i.test(url)) {
495
536
  return true;
496
- }
537
+ } // Absolute URLs
497
538
 
498
- return false;
499
- }
500
539
 
501
- function isUrlRequestable(url) {
502
- if (matchNativeWin32Path.test(url)) {
540
+ if (/^[a-z][a-z0-9+.-]*:/i.test(url) && !matchNativeWin32Path.test(url)) {
503
541
  return false;
504
- }
542
+ } // `#` URLs
505
543
 
506
- if (mayBeServerRelativeUrl(url)) {
507
- return true;
508
- }
509
544
 
510
- if (/^file:/i.test(url)) {
511
- return true;
545
+ if (/^#/.test(url)) {
546
+ return false;
512
547
  }
513
548
 
514
- return (0, _loaderUtils.isUrlRequest)(url);
549
+ return true;
515
550
  }
516
551
 
517
552
  function sort(a, b) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-loader",
3
- "version": "4.0.0",
3
+ "version": "4.2.1",
4
4
  "description": "css loader module for webpack",
5
5
  "license": "MIT",
6
6
  "repository": "webpack-contrib/css-loader",