css-loader 6.7.0 → 6.7.2

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/README.md CHANGED
@@ -9,7 +9,6 @@
9
9
 
10
10
  [![npm][npm]][npm-url]
11
11
  [![node][node]][node-url]
12
- [![deps][deps]][deps-url]
13
12
  [![tests][tests]][tests-url]
14
13
  [![coverage][cover]][cover-url]
15
14
  [![chat][chat]][chat-url]
@@ -21,7 +20,9 @@ The `css-loader` interprets `@import` and `url()` like `import/require()` and wi
21
20
 
22
21
  ## Getting Started
23
22
 
24
- > ⚠ To use css-loader, webpack@5 is required
23
+ > **Warning**
24
+ >
25
+ > To use css-loader, webpack@5 is required
25
26
 
26
27
  To begin, you'll need to install `css-loader`:
27
28
 
@@ -86,7 +87,7 @@ Type:
86
87
  type url =
87
88
  | boolean
88
89
  | {
89
- url: (url: string, resourcePath: string) => boolean;
90
+ filter: (url: string, resourcePath: string) => boolean;
90
91
  };
91
92
  ```
92
93
 
@@ -161,6 +162,11 @@ module.exports = {
161
162
  return false;
162
163
  }
163
164
 
165
+ // Don't handle images under root-relatve /external_images/
166
+ if (/^\/external_images\//.test(path)) {
167
+ return false;
168
+ }
169
+
164
170
  return true;
165
171
  },
166
172
  },
@@ -398,7 +404,9 @@ The loader replaces local selectors with unique identifiers. The chosen unique i
398
404
  }
399
405
  ```
400
406
 
401
- > ℹ️ Identifiers are exported
407
+ > **Note**
408
+ >
409
+ > Identifiers are exported
402
410
 
403
411
  ```js
404
412
  exports.locals = {
@@ -451,7 +459,9 @@ exports.locals = {
451
459
 
452
460
  To import a local classname from another module.
453
461
 
454
- > i We strongly recommend that you specify the extension when importing a file, since it is possible to import a file with any extension and it is not known in advance which file to use.
462
+ > **Note**
463
+ >
464
+ > We strongly recommend that you specify the extension when importing a file, since it is possible to import a file with any extension and it is not known in advance which file to use.
455
465
 
456
466
  ```css
457
467
  :local(.continueButton) {
@@ -631,7 +641,7 @@ module.exports = {
631
641
 
632
642
  ###### `RegExp`
633
643
 
634
- Enable css modules for files based on the filename satisfying your regex check.
644
+ Enable CSS modules for files based on the filename satisfying your regex check.
635
645
 
636
646
  **webpack.config.js**
637
647
 
@@ -655,7 +665,7 @@ module.exports = {
655
665
 
656
666
  ###### `function`
657
667
 
658
- Enable css modules for files based on the filename satisfying your filter function check.
668
+ Enable CSS modules for files based on the filename satisfying your filter function check.
659
669
 
660
670
  **webpack.config.js**
661
671
 
@@ -1099,9 +1109,13 @@ Default: `false`
1099
1109
 
1100
1110
  Enables/disables ES modules named export for locals.
1101
1111
 
1102
- > ⚠ Names of locals are converted to camelcase, i.e. the `exportLocalsConvention` option has `camelCaseOnly` value by default.
1112
+ > **Warning**
1113
+ >
1114
+ > Names of locals are converted to camelcase, i.e. the `exportLocalsConvention` option has `camelCaseOnly` value by default.
1103
1115
 
1104
- > ⚠ It is not allowed to use JavaScript reserved words in css class names.
1116
+ > **Warning**
1117
+ >
1118
+ > It is not allowed to use JavaScript reserved words in css class names.
1105
1119
 
1106
1120
  **styles.css**
1107
1121
 
@@ -1202,7 +1216,9 @@ Style of exported class names.
1202
1216
 
1203
1217
  By default, the exported JSON keys mirror the class names (i.e `asIs` value).
1204
1218
 
1205
- > ⚠ Only `camelCaseOnly` value allowed if you set the `namedExport` value to `true`.
1219
+ > **Warning**
1220
+ >
1221
+ > Only `camelCaseOnly` value allowed if you set the `namedExport` value to `true`.
1206
1222
 
1207
1223
  | Name | Type | Description |
1208
1224
  | :-------------------: | :------: | :----------------------------------------------------------------------------------------------- |
@@ -1508,8 +1524,13 @@ import "./styles.css";
1508
1524
 
1509
1525
  #### `'string'`
1510
1526
 
1511
- > ⚠ You don't need [`style-loader`](https://github.com/webpack-contrib/style-loader) anymore, please remove it.
1512
- > ⚠ The `esModules` option should be enabled if you want to use it with [`CSS modules`](https://github.com/webpack-contrib/css-loader#modules), by default for locals will be used [named export](https://github.com/webpack-contrib/css-loader#namedexport).
1527
+ > **Warning**
1528
+ >
1529
+ > You don't need [`style-loader`](https://github.com/webpack-contrib/style-loader) anymore, please remove it.
1530
+
1531
+ > **Warning**
1532
+ >
1533
+ > The `esModules` option should be enabled if you want to use it with [`CSS modules`](https://github.com/webpack-contrib/css-loader#modules), by default for locals will be used [named export](https://github.com/webpack-contrib/css-loader#namedexport).
1513
1534
 
1514
1535
  The default export is `string`.
1515
1536
 
@@ -1538,10 +1559,21 @@ console.log(sheet);
1538
1559
 
1539
1560
  #### `'css-style-sheet'`
1540
1561
 
1541
- > ⚠ `@import` rules not yet allowed, more [information](https://web.dev/css-module-scripts/#@import-rules-not-yet-allowed)
1542
- > ⚠ You don't need [`style-loader`](https://github.com/webpack-contrib/style-loader) anymore, please remove it.
1543
- > ⚠ The `esModules` option should be enabled if you want to use it with [`CSS modules`](https://github.com/webpack-contrib/css-loader#modules), by default for locals will be used [named export](https://github.com/webpack-contrib/css-loader#namedexport).
1544
- > ⚠ Source maps are not currently supported in `Chrome` due [bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1174094&q=CSSStyleSheet%20source%20maps&can=2)
1562
+ > **Warning**
1563
+ >
1564
+ > `@import` rules not yet allowed, more [information](https://web.dev/css-module-scripts/#@import-rules-not-yet-allowed)
1565
+
1566
+ > **Warning**
1567
+ >
1568
+ > You don't need [`style-loader`](https://github.com/webpack-contrib/style-loader) anymore, please remove it.
1569
+
1570
+ > **Warning**
1571
+ >
1572
+ > The `esModules` option should be enabled if you want to use it with [`CSS modules`](https://github.com/webpack-contrib/css-loader#modules), by default for locals will be used [named export](https://github.com/webpack-contrib/css-loader#namedexport).
1573
+
1574
+ > **Warning**
1575
+ >
1576
+ > Source maps are not currently supported in `Chrome` due [bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1174094&q=CSSStyleSheet%20source%20maps&can=2)
1545
1577
 
1546
1578
  The default export is a [constructable stylesheet](https://developers.google.com/web/updates/2019/02/constructable-stylesheets) (i.e. [`CSSStyleSheet`](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet)).
1547
1579
 
@@ -1650,7 +1682,9 @@ For `production` builds it's recommended to extract the CSS from your bundle bei
1650
1682
  This can be achieved by using the [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin), because it creates separate css files.
1651
1683
  For `development` mode (including `webpack-dev-server`) you can use [style-loader](https://github.com/webpack-contrib/style-loader), because it injects CSS into the DOM using multiple <style></style> and works faster.
1652
1684
 
1653
- > i Do not use `style-loader` and `mini-css-extract-plugin` together.
1685
+ > **Note**
1686
+ >
1687
+ > Do not use `style-loader` and `mini-css-extract-plugin` together.
1654
1688
 
1655
1689
  **webpack.config.js**
1656
1690
 
@@ -1988,8 +2022,6 @@ Please take a moment to read our contributing guidelines if you haven't yet done
1988
2022
  [npm-url]: https://npmjs.com/package/css-loader
1989
2023
  [node]: https://img.shields.io/node/v/css-loader.svg
1990
2024
  [node-url]: https://nodejs.org
1991
- [deps]: https://david-dm.org/webpack-contrib/css-loader.svg
1992
- [deps-url]: https://david-dm.org/webpack-contrib/css-loader
1993
2025
  [tests]: https://github.com/webpack-contrib/css-loader/workflows/css-loader/badge.svg
1994
2026
  [tests-url]: https://github.com/webpack-contrib/css-loader/actions
1995
2027
  [cover]: https://codecov.io/gh/webpack-contrib/css-loader/branch/master/graph/badge.svg
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  class CssSyntaxError extends Error {
9
8
  constructor(error) {
10
9
  super(error);
@@ -14,27 +13,23 @@ class CssSyntaxError extends Error {
14
13
  column,
15
14
  file
16
15
  } = error;
17
- this.name = "CssSyntaxError"; // Based on https://github.com/postcss/postcss/blob/master/lib/css-syntax-error.es6#L132
18
- // We don't need `plugin` and `file` properties.
16
+ this.name = "CssSyntaxError";
19
17
 
18
+ // Based on https://github.com/postcss/postcss/blob/master/lib/css-syntax-error.es6#L132
19
+ // We don't need `plugin` and `file` properties.
20
20
  this.message = `${this.name}\n\n`;
21
-
22
21
  if (typeof line !== "undefined") {
23
22
  this.message += `(${line}:${column}) `;
24
23
  }
25
-
26
24
  this.message += file ? `${file} ` : "<css input> ";
27
25
  this.message += `${reason}`;
28
26
  const code = error.showSourceCode();
29
-
30
27
  if (code) {
31
28
  this.message += `\n\n${code}\n`;
32
- } // We don't need stack https://github.com/postcss/postcss/blob/master/docs/guidelines/runner.md#31-dont-show-js-stack-for-csssyntaxerror
33
-
29
+ }
34
30
 
31
+ // We don't need stack https://github.com/postcss/postcss/blob/master/docs/guidelines/runner.md#31-dont-show-js-stack-for-csssyntaxerror
35
32
  this.stack = false;
36
33
  }
37
-
38
34
  }
39
-
40
35
  exports.default = CssSyntaxError;
package/dist/Warning.js CHANGED
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  class Warning extends Error {
9
8
  constructor(warning) {
10
9
  super(warning);
@@ -13,20 +12,18 @@ class Warning extends Error {
13
12
  line,
14
13
  column
15
14
  } = warning;
16
- this.name = "Warning"; // Based on https://github.com/postcss/postcss/blob/master/lib/warning.es6#L74
17
- // We don't need `plugin` properties.
15
+ this.name = "Warning";
18
16
 
17
+ // Based on https://github.com/postcss/postcss/blob/master/lib/warning.es6#L74
18
+ // We don't need `plugin` properties.
19
19
  this.message = `${this.name}\n\n`;
20
-
21
20
  if (typeof line !== "undefined") {
22
21
  this.message += `(${line}:${column}) `;
23
22
  }
23
+ this.message += `${text}`;
24
24
 
25
- this.message += `${text}`; // We don't need stack https://github.com/postcss/postcss/blob/master/docs/guidelines/runner.md#31-dont-show-js-stack-for-csssyntaxerror
26
-
25
+ // We don't need stack https://github.com/postcss/postcss/blob/master/docs/guidelines/runner.md#31-dont-show-js-stack-for-csssyntaxerror
27
26
  this.stack = false;
28
27
  }
29
-
30
28
  }
31
-
32
29
  exports.default = Warning;
package/dist/cjs.js CHANGED
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
 
3
3
  const loader = require("./index");
4
-
5
- module.exports.defaultGetLocalIdent = require("./utils").defaultGetLocalIdent;
6
- module.exports = loader.default;
4
+ module.exports = loader.default;
5
+ module.exports.defaultGetLocalIdent = require("./utils").defaultGetLocalIdent;
package/dist/index.js CHANGED
@@ -4,59 +4,45 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = loader;
7
-
8
7
  var _postcss = _interopRequireDefault(require("postcss"));
9
-
10
8
  var _package = _interopRequireDefault(require("postcss/package.json"));
11
-
12
9
  var _semver = require("semver");
13
-
14
10
  var _CssSyntaxError = _interopRequireDefault(require("./CssSyntaxError"));
15
-
16
11
  var _Warning = _interopRequireDefault(require("./Warning"));
17
-
18
12
  var _options = _interopRequireDefault(require("./options.json"));
19
-
20
13
  var _plugins = require("./plugins");
21
-
22
14
  var _utils = require("./utils");
23
-
24
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
16
  /*
27
17
  MIT License http://www.opensource.org/licenses/mit-license.php
28
18
  Author Tobias Koppers @sokra
29
19
  */
20
+
30
21
  async function loader(content, map, meta) {
31
22
  const rawOptions = this.getOptions(_options.default);
32
23
  const plugins = [];
33
24
  const callback = this.async();
34
25
  let options;
35
-
36
26
  try {
37
27
  options = (0, _utils.normalizeOptions)(rawOptions, this);
38
28
  } catch (error) {
39
29
  callback(error);
40
30
  return;
41
31
  }
42
-
43
32
  const replacements = [];
44
33
  const exports = [];
45
-
46
34
  if ((0, _utils.shouldUseModulesPlugins)(options)) {
47
35
  plugins.push(...(0, _utils.getModulesPlugins)(options, this));
48
36
  }
49
-
50
37
  const importPluginImports = [];
51
38
  const importPluginApi = [];
52
- let isSupportAbsoluteURL = false; // TODO enable by default in the next major release
39
+ let isSupportAbsoluteURL = false;
53
40
 
41
+ // TODO enable by default in the next major release
54
42
  if (this._compilation && this._compilation.options && this._compilation.options.experiments && this._compilation.options.experiments.buildHttp) {
55
43
  isSupportAbsoluteURL = true;
56
44
  }
57
-
58
45
  const isSupportDataURL = options.esModule && Boolean("fsStartTime" in this._compiler);
59
-
60
46
  if ((0, _utils.shouldUseImportPlugin)(options)) {
61
47
  plugins.push((0, _plugins.importParser)({
62
48
  isSupportAbsoluteURL: false,
@@ -69,9 +55,7 @@ async function loader(content, map, meta) {
69
55
  urlHandler: url => (0, _utils.stringifyRequest)(this, (0, _utils.combineRequests)((0, _utils.getPreRequester)(this)(options.importLoaders), url))
70
56
  }));
71
57
  }
72
-
73
58
  const urlPluginImports = [];
74
-
75
59
  if ((0, _utils.shouldUseURLPlugin)(options)) {
76
60
  const needToResolveURL = !options.esModule;
77
61
  plugins.push((0, _plugins.urlParser)({
@@ -85,17 +69,17 @@ async function loader(content, map, meta) {
85
69
  resolver: needToResolveURL ? this.getResolve({
86
70
  mainFiles: [],
87
71
  extensions: []
88
- }) : // eslint-disable-next-line no-undefined
72
+ }) :
73
+ // eslint-disable-next-line no-undefined
89
74
  undefined,
90
- urlHandler: url => (0, _utils.stringifyRequest)(this, url) // Support data urls as input in new URL added in webpack@5.38.0
91
-
75
+ urlHandler: url => (0, _utils.stringifyRequest)(this, url)
76
+ // Support data urls as input in new URL added in webpack@5.38.0
92
77
  }));
93
78
  }
94
79
 
95
80
  const icssPluginImports = [];
96
81
  const icssPluginApi = [];
97
82
  const needToUseIcssPlugin = (0, _utils.shouldUseIcssPlugin)(options);
98
-
99
83
  if (needToUseIcssPlugin) {
100
84
  plugins.push((0, _plugins.icssParser)({
101
85
  loaderContext: this,
@@ -105,25 +89,22 @@ async function loader(content, map, meta) {
105
89
  exports,
106
90
  urlHandler: url => (0, _utils.stringifyRequest)(this, (0, _utils.combineRequests)((0, _utils.getPreRequester)(this)(options.importLoaders), url))
107
91
  }));
108
- } // Reuse CSS AST (PostCSS AST e.g 'postcss-loader') to avoid reparsing
109
-
92
+ }
110
93
 
94
+ // Reuse CSS AST (PostCSS AST e.g 'postcss-loader') to avoid reparsing
111
95
  if (meta) {
112
96
  const {
113
97
  ast
114
98
  } = meta;
115
-
116
99
  if (ast && ast.type === "postcss" && (0, _semver.satisfies)(ast.version, `^${_package.default.version}`)) {
117
100
  // eslint-disable-next-line no-param-reassign
118
101
  content = ast.root;
119
102
  }
120
103
  }
121
-
122
104
  const {
123
105
  resourcePath
124
106
  } = this;
125
107
  let result;
126
-
127
108
  try {
128
109
  result = await (0, _postcss.default)(plugins).process(content, {
129
110
  hideNothingWarning: true,
@@ -139,25 +120,20 @@ async function loader(content, map, meta) {
139
120
  if (error.file) {
140
121
  this.addDependency(error.file);
141
122
  }
142
-
143
123
  callback(error.name === "CssSyntaxError" ? new _CssSyntaxError.default(error) : error);
144
124
  return;
145
125
  }
146
-
147
126
  for (const warning of result.warnings()) {
148
127
  this.emitWarning(new _Warning.default(warning));
149
128
  }
150
-
151
129
  const imports = [].concat(icssPluginImports.sort(_utils.sort)).concat(importPluginImports.sort(_utils.sort)).concat(urlPluginImports.sort(_utils.sort));
152
130
  const api = [].concat(importPluginApi.sort(_utils.sort)).concat(icssPluginApi.sort(_utils.sort));
153
-
154
131
  if (options.modules.exportOnlyLocals !== true) {
155
132
  imports.unshift({
156
133
  type: "api_import",
157
134
  importName: "___CSS_LOADER_API_IMPORT___",
158
135
  url: (0, _utils.stringifyRequest)(this, require.resolve("./runtime/api"))
159
136
  });
160
-
161
137
  if (options.sourceMap) {
162
138
  imports.unshift({
163
139
  importName: "___CSS_LOADER_API_SOURCEMAP_IMPORT___",
@@ -170,17 +146,14 @@ async function loader(content, map, meta) {
170
146
  });
171
147
  }
172
148
  }
173
-
174
149
  const importCode = (0, _utils.getImportCode)(imports, options);
175
150
  let moduleCode;
176
-
177
151
  try {
178
152
  moduleCode = (0, _utils.getModuleCode)(result, api, replacements, options, this);
179
153
  } catch (error) {
180
154
  callback(error);
181
155
  return;
182
156
  }
183
-
184
157
  const exportCode = (0, _utils.getExportCode)(exports, replacements, needToUseIcssPlugin, options);
185
158
  callback(null, `${importCode}${moduleCode}${exportCode}`);
186
159
  }
@@ -21,11 +21,7 @@ Object.defineProperty(exports, "urlParser", {
21
21
  return _postcssUrlParser.default;
22
22
  }
23
23
  });
24
-
25
24
  var _postcssImportParser = _interopRequireDefault(require("./postcss-import-parser"));
26
-
27
25
  var _postcssIcssParser = _interopRequireDefault(require("./postcss-icss-parser"));
28
-
29
26
  var _postcssUrlParser = _interopRequireDefault(require("./postcss-url-parser"));
30
-
31
27
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -4,15 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _icssUtils = require("icss-utils");
9
-
10
8
  var _utils = require("../utils");
11
-
12
9
  const plugin = (options = {}) => {
13
10
  return {
14
11
  postcssPlugin: "postcss-icss-parser",
15
-
16
12
  async OnceExit(root) {
17
13
  const importReplacements = Object.create(null);
18
14
  const {
@@ -31,59 +27,48 @@ const plugin = (options = {}) => {
31
27
  mainFields: ["css", "style", "main", "..."],
32
28
  mainFiles: ["index", "..."],
33
29
  preferRelative: true
34
- }); // eslint-disable-next-line guard-for-in
30
+ });
35
31
 
32
+ // eslint-disable-next-line guard-for-in
36
33
  for (const url in icssImports) {
37
34
  const tokens = icssImports[url];
38
-
39
35
  if (Object.keys(tokens).length === 0) {
40
36
  // eslint-disable-next-line no-continue
41
37
  continue;
42
38
  }
43
-
44
39
  let normalizedUrl = url;
45
40
  let prefix = "";
46
41
  const queryParts = normalizedUrl.split("!");
47
-
48
42
  if (queryParts.length > 1) {
49
43
  normalizedUrl = queryParts.pop();
50
44
  prefix = queryParts.join("!");
51
45
  }
52
-
53
46
  const request = (0, _utils.requestify)((0, _utils.normalizeUrl)(normalizedUrl, true), loaderContext.rootContext);
54
-
55
47
  const doResolve = async () => {
56
48
  const resolvedUrl = await (0, _utils.resolveRequests)(resolver, loaderContext.context, [...new Set([normalizedUrl, request])]);
57
-
58
49
  if (!resolvedUrl) {
59
50
  return;
60
- } // eslint-disable-next-line consistent-return
61
-
51
+ }
62
52
 
53
+ // eslint-disable-next-line consistent-return
63
54
  return {
64
55
  url: resolvedUrl,
65
56
  prefix,
66
57
  tokens
67
58
  };
68
59
  };
69
-
70
60
  tasks.push(doResolve());
71
61
  }
72
-
73
62
  const results = await Promise.all(tasks);
74
-
75
63
  for (let index = 0; index <= results.length - 1; index++) {
76
64
  const item = results[index];
77
-
78
65
  if (!item) {
79
66
  // eslint-disable-next-line no-continue
80
67
  continue;
81
68
  }
82
-
83
69
  const newUrl = item.prefix ? `${item.prefix}!${item.url}` : item.url;
84
70
  const importKey = newUrl;
85
71
  let importName = imports.get(importKey);
86
-
87
72
  if (!importName) {
88
73
  importName = `___CSS_LOADER_ICSS_IMPORT_${imports.size}___`;
89
74
  imports.set(importKey, importName);
@@ -100,7 +85,6 @@ const plugin = (options = {}) => {
100
85
  index
101
86
  });
102
87
  }
103
-
104
88
  for (const [replacementIndex, token] of Object.keys(item.tokens).entries()) {
105
89
  const replacementName = `___CSS_LOADER_ICSS_IMPORT_${index}_REPLACEMENT_${replacementIndex}___`;
106
90
  const localName = item.tokens[token];
@@ -112,11 +96,9 @@ const plugin = (options = {}) => {
112
96
  });
113
97
  }
114
98
  }
115
-
116
99
  if (Object.keys(importReplacements).length > 0) {
117
100
  (0, _icssUtils.replaceSymbols)(root, importReplacements);
118
101
  }
119
-
120
102
  for (const name of Object.keys(icssExports)) {
121
103
  const value = (0, _icssUtils.replaceValueSymbols)(icssExports[name], importReplacements);
122
104
  options.exports.push({
@@ -125,10 +107,8 @@ const plugin = (options = {}) => {
125
107
  });
126
108
  }
127
109
  }
128
-
129
110
  };
130
111
  };
131
-
132
112
  plugin.postcss = true;
133
113
  var _default = plugin;
134
114
  exports.default = _default;