css-loader 4.1.0 → 4.2.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/CHANGELOG.md CHANGED
@@ -2,6 +2,34 @@
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.2](https://github.com/webpack-contrib/css-loader/compare/v4.2.1...v4.2.2) (2020-08-24)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * source maps generation, source from source maps are now relative to `compiler.context` and use `webpack://` protocol ([#1169](https://github.com/webpack-contrib/css-loader/issues/1169)) ([fb5c53d](https://github.com/webpack-contrib/css-loader/commit/fb5c53d80b10ee698762238bb7b122aec8c5048d))
11
+
12
+ ### [4.2.1](https://github.com/webpack-contrib/css-loader/compare/v4.2.0...v4.2.1) (2020-08-06)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * 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))
18
+
19
+ ## [4.2.0](https://github.com/webpack-contrib/css-loader/compare/v4.1.1...v4.2.0) (2020-07-31)
20
+
21
+
22
+ ### Features
23
+
24
+ * 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))
25
+
26
+ ### [4.1.1](https://github.com/webpack-contrib/css-loader/compare/v4.1.0...v4.1.1) (2020-07-30)
27
+
28
+
29
+ ### Bug Fixes
30
+
31
+ * remove unnecessary `console` call ([#1148](https://github.com/webpack-contrib/css-loader/issues/1148)) ([b1b90ca](https://github.com/webpack-contrib/css-loader/commit/b1b90caaea8eb045177749729340c7906454a84b))
32
+
5
33
  ## [4.1.0](https://github.com/webpack-contrib/css-loader/compare/v4.0.0...v4.1.0) (2020-07-29)
6
34
 
7
35
 
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`
@@ -918,7 +951,7 @@ module.exports = {
918
951
  };
919
952
  ```
920
953
 
921
- ##### `exportlocalsConvention`
954
+ ##### `exportLocalsConvention`
922
955
 
923
956
  Type: `String`
924
957
  Default: based on the `modules.namedExport` option value, if `true` - `camelCaseOnly`, otherwise `asIs`
@@ -1000,33 +1033,6 @@ module.exports = {
1000
1033
  };
1001
1034
  ```
1002
1035
 
1003
- ### `icss`
1004
-
1005
- Type: Boolean Default: `true` if `modules` are enabled, false otherwise
1006
-
1007
- Enables/disables handling of the low level "Interoperable CSS" format for declaring
1008
- import and export dependencies between CSS and other languages. ICSS enables
1009
- CSS Module support, and is enabled automatically when `modules` are enabled. It
1010
- can also be enabled independently to allow other loaders to handle processing CSS modules.
1011
-
1012
- **webpack.config.js**
1013
-
1014
- ```js
1015
- module.exports = {
1016
- module: {
1017
- rules: [
1018
- {
1019
- test: /\.css$/i,
1020
- loader: 'css-loader',
1021
- options: {
1022
- icss: true,
1023
- },
1024
- },
1025
- ],
1026
- },
1027
- };
1028
- ```
1029
-
1030
1036
  ### `sourceMap`
1031
1037
 
1032
1038
  Type: `Boolean`
@@ -1237,6 +1243,111 @@ module.exports = {
1237
1243
  };
1238
1244
  ```
1239
1245
 
1246
+ ### Separating `Interoperable CSS`-only and `CSS Module` features
1247
+
1248
+ The following setup is an example of allowing `Interoperable CSS` features only (such as `:import` and `:export`) without using further `CSS Module` functionality by setting `compileType` option for all files that do not match `*.module.scss` naming convention. This is for reference as having `ICSS` features applied to all files was default `css-loader` behavior before v4.
1249
+ Meanwhile all files matching `*.module.scss` are treated as `CSS Modules` in this example.
1250
+
1251
+ An example case is assumed where a project requires canvas drawing variables to be synchronized with CSS - canvas drawing uses the same color (set by color name in JavaScript) as HTML background (set by class name in CSS).
1252
+
1253
+ **webpack.config.js**
1254
+
1255
+ ```js
1256
+ module.exports = {
1257
+ module: {
1258
+ rules: [
1259
+ // ...
1260
+ // --------
1261
+ // SCSS ALL EXCEPT MODULES
1262
+ {
1263
+ test: /\.scss$/,
1264
+ exclude: /\.module\.scss$/,
1265
+ use: [
1266
+ {
1267
+ loader: 'style-loader'
1268
+ },
1269
+ {
1270
+ loader: 'css-loader',
1271
+ options: {
1272
+ importLoaders: 1,
1273
+ modules: {
1274
+ compileType: 'icss'
1275
+ }
1276
+ }
1277
+ },
1278
+ {
1279
+ loader: 'sass-loader'
1280
+ },
1281
+ ],
1282
+ },
1283
+ // --------
1284
+ // SCSS MODULES
1285
+ {
1286
+ test: /\.module\.scss$/,
1287
+ use: [
1288
+ {
1289
+ loader: 'style-loader'
1290
+ },
1291
+ {
1292
+ loader: 'css-loader',
1293
+ options: {
1294
+ importLoaders: 1,
1295
+ modules: {
1296
+ compileType: 'module'
1297
+ }
1298
+ }
1299
+ },
1300
+ {
1301
+ loader: 'sass-loader'
1302
+ },
1303
+ ],
1304
+ },
1305
+ // --------
1306
+ // ...
1307
+ },
1308
+ };
1309
+ ```
1310
+
1311
+ **variables.scss**
1312
+
1313
+ File treated as `ICSS`-only.
1314
+
1315
+ ```scss
1316
+ $colorBackground: red;
1317
+ :export {
1318
+ colorBackgroundCanvas: $colorBackground;
1319
+ }
1320
+ ```
1321
+
1322
+ **Component.module.scss**
1323
+
1324
+ File treated as `CSS Module`.
1325
+
1326
+ ```scss
1327
+ @import 'variables.scss';
1328
+ .componentClass {
1329
+ background-color: $colorBackground;
1330
+ }
1331
+ ```
1332
+
1333
+ **Component.jsx**
1334
+
1335
+ Using both `CSS Module` functionality as well as SCSS variables directly in JavaScript.
1336
+
1337
+ ```jsx
1338
+ import svars from 'variables.scss';
1339
+ import styles from 'Component.module.scss';
1340
+
1341
+ // Render DOM with CSS modules class name
1342
+ // <div className={styles.componentClass}>
1343
+ // <canvas ref={mountsCanvas}/>
1344
+ // </div>
1345
+
1346
+ // Somewhere in JavaScript canvas drawing code use the variable directly
1347
+ // const ctx = mountsCanvas.current.getContext('2d',{alpha: false});
1348
+ ctx.fillStyle = `${svars.colorBackgroundCanvas}`;
1349
+ ```
1350
+
1240
1351
  ## Contributing
1241
1352
 
1242
1353
  Please take a moment to read our contributing guidelines if you haven't yet done so.
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
 
@@ -101,7 +100,7 @@ async function loader(content, map, meta) {
101
100
  const icssPluginImports = [];
102
101
  const icssPluginApi = [];
103
102
 
104
- if (needUseModulesPlugins || options.icss) {
103
+ if ((0, _utils.shouldUseIcssPlugin)(options)) {
105
104
  const icssResolver = this.getResolve({
106
105
  conditionNames: ['style'],
107
106
  extensions: [],
@@ -132,15 +131,17 @@ async function loader(content, map, meta) {
132
131
  }
133
132
  }
134
133
 
134
+ const {
135
+ resourcePath
136
+ } = this;
135
137
  let result;
136
138
 
137
139
  try {
138
140
  result = await (0, _postcss.default)(plugins).process(content, {
139
- from: this.resourcePath,
140
- to: this.resourcePath,
141
+ from: resourcePath,
142
+ to: resourcePath,
141
143
  map: options.sourceMap ? {
142
- // Some loaders (example `"postcss-loader": "1.x.x"`) always generates source map, we should remove it
143
- prev: map ? (0, _utils.normalizeSourceMap)(map) : null,
144
+ prev: map ? (0, _utils.normalizeSourceMap)(map, resourcePath) : null,
144
145
  inline: false,
145
146
  annotation: false
146
147
  } : false
@@ -169,7 +170,7 @@ async function loader(content, map, meta) {
169
170
  }
170
171
 
171
172
  const importCode = (0, _utils.getImportCode)(imports, options);
172
- const moduleCode = (0, _utils.getModuleCode)(result, api, replacements, options);
173
+ const moduleCode = (0, _utils.getModuleCode)(result, api, replacements, options, this);
173
174
  const exportCode = (0, _utils.getExportCode)(exports, replacements, options);
174
175
  callback(null, `${importCode}${moduleCode}${exportCode}`);
175
176
  }
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": [
@@ -251,7 +251,6 @@ var _default = _postcss.default.plugin(pluginName, options => async (css, result
251
251
  decl.value = parsed.toString();
252
252
  }
253
253
 
254
- console.timeEnd('URL');
255
254
  return Promise.resolve();
256
255
  });
257
256
 
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;
@@ -27,8 +28,6 @@ var _path = _interopRequireDefault(require("path"));
27
28
 
28
29
  var _loaderUtils = require("loader-utils");
29
30
 
30
- var _normalizePath = _interopRequireDefault(require("normalize-path"));
31
-
32
31
  var _cssesc = _interopRequireDefault(require("cssesc"));
33
32
 
34
33
  var _postcssModulesValues = _interopRequireDefault(require("postcss-modules-values"));
@@ -65,6 +64,10 @@ function unescape(str) {
65
64
  String.fromCharCode(high >> 10 | 0xd800, high & 0x3ff | 0xdc00);
66
65
  /* eslint-enable line-comment-position */
67
66
  });
67
+ }
68
+
69
+ function normalizePath(file) {
70
+ return _path.default.sep === '\\' ? file.replace(/\\/g, '/') : file;
68
71
  } // eslint-disable-next-line no-control-regex
69
72
 
70
73
 
@@ -80,7 +83,7 @@ function defaultGetLocalIdent(loaderContext, localIdentName, localName, options)
80
83
  const {
81
84
  resourcePath
82
85
  } = loaderContext;
83
- const request = (0, _normalizePath.default)(_path.default.relative(context, resourcePath)); // eslint-disable-next-line no-param-reassign
86
+ const request = normalizePath(_path.default.relative(context, resourcePath)); // eslint-disable-next-line no-param-reassign
84
87
 
85
88
  options.content = `${hashPrefix + request}\x00${unescape(localName)}`; // Using `[path]` placeholder outputs `/` we need escape their
86
89
  // Also directories can contains invalid characters for css we need escape their too
@@ -141,6 +144,7 @@ function getModulesOptions(rawOptions, loaderContext) {
141
144
  }
142
145
 
143
146
  let modulesOptions = {
147
+ compileType: rawOptions.icss ? 'icss' : 'module',
144
148
  auto: true,
145
149
  mode: 'local',
146
150
  exportGlobals: false,
@@ -207,12 +211,17 @@ function getModulesOptions(rawOptions, loaderContext) {
207
211
  }
208
212
 
209
213
  function normalizeOptions(rawOptions, loaderContext) {
214
+ if (rawOptions.icss) {
215
+ loaderContext.emitWarning(new Error('The "icss" option is deprecated, use "modules.compileType: "icss"" instead'));
216
+ }
217
+
210
218
  const modulesOptions = getModulesOptions(rawOptions, loaderContext);
211
219
  return {
212
220
  url: typeof rawOptions.url === 'undefined' ? true : rawOptions.url,
213
221
  import: typeof rawOptions.import === 'undefined' ? true : rawOptions.import,
214
222
  modules: modulesOptions,
215
- icss: modulesOptions ? true : rawOptions.icss,
223
+ // TODO remove in the next major release
224
+ icss: typeof rawOptions.icss === 'undefined' ? false : rawOptions.icss,
216
225
  sourceMap: typeof rawOptions.sourceMap === 'boolean' ? rawOptions.sourceMap : loaderContext.sourceMap,
217
226
  importLoaders: rawOptions.importLoaders,
218
227
  esModule: typeof rawOptions.esModule === 'undefined' ? true : rawOptions.esModule
@@ -244,7 +253,11 @@ function shouldUseURLPlugin(options) {
244
253
  }
245
254
 
246
255
  function shouldUseModulesPlugins(options) {
247
- return Boolean(options.modules);
256
+ return options.modules.compileType === 'module';
257
+ }
258
+
259
+ function shouldUseIcssPlugin(options) {
260
+ return options.icss === true || Boolean(options.modules);
248
261
  }
249
262
 
250
263
  function getModulesPlugins(options, loaderContext) {
@@ -279,26 +292,57 @@ function getModulesPlugins(options, loaderContext) {
279
292
  return plugins;
280
293
  }
281
294
 
282
- function normalizeSourceMap(map) {
295
+ const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
296
+ const ABSOLUTE_SCHEME = /^[a-z0-9+\-.]+:/i;
297
+
298
+ function getURLType(source) {
299
+ if (source[0] === '/') {
300
+ if (source[1] === '/') {
301
+ return 'scheme-relative';
302
+ }
303
+
304
+ return 'path-absolute';
305
+ }
306
+
307
+ if (IS_NATIVE_WIN32_PATH.test(source)) {
308
+ return 'path-absolute';
309
+ }
310
+
311
+ return ABSOLUTE_SCHEME.test(source) ? 'absolute' : 'path-relative';
312
+ }
313
+
314
+ function normalizeSourceMap(map, resourcePath) {
283
315
  let newMap = map; // Some loader emit source map as string
284
316
  // Strip any JSON XSSI avoidance prefix from the string (as documented in the source maps specification), and then parse the string as JSON.
285
317
 
286
318
  if (typeof newMap === 'string') {
287
319
  newMap = JSON.parse(newMap);
288
- } // Source maps should use forward slash because it is URLs (https://github.com/mozilla/source-map/issues/91)
289
- // We should normalize path because previous loaders like `sass-loader` using backslash when generate source map
290
-
291
-
292
- if (newMap.file) {
293
- newMap.file = (0, _normalizePath.default)(newMap.file);
294
320
  }
295
321
 
296
- if (newMap.sourceRoot) {
297
- newMap.sourceRoot = (0, _normalizePath.default)(newMap.sourceRoot);
298
- }
322
+ delete newMap.file;
323
+ const {
324
+ sourceRoot
325
+ } = newMap;
326
+ delete newMap.sourceRoot;
299
327
 
300
328
  if (newMap.sources) {
301
- newMap.sources = newMap.sources.map(source => (0, _normalizePath.default)(source));
329
+ // Source maps should use forward slash because it is URLs (https://github.com/mozilla/source-map/issues/91)
330
+ // We should normalize path because previous loaders like `sass-loader` using backslash when generate source map
331
+ newMap.sources = newMap.sources.map(source => {
332
+ // Non-standard syntax from `postcss`
333
+ if (source.indexOf('<') === 0) {
334
+ return source;
335
+ }
336
+
337
+ const sourceType = getURLType(source); // Do no touch `scheme-relative` and `absolute` URLs
338
+
339
+ if (sourceType === 'path-relative' || sourceType === 'path-absolute') {
340
+ const absoluteSource = sourceType === 'path-relative' && sourceRoot ? _path.default.resolve(sourceRoot, normalizePath(source)) : normalizePath(source);
341
+ return _path.default.relative(_path.default.dirname(resourcePath), absoluteSource);
342
+ }
343
+
344
+ return source;
345
+ });
302
346
  }
303
347
 
304
348
  return newMap;
@@ -334,23 +378,58 @@ function getImportCode(imports, options) {
334
378
  url,
335
379
  icss
336
380
  } = item;
337
- 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`;
381
+
382
+ if (options.esModule) {
383
+ if (icss && options.modules.namedExport) {
384
+ code += `import ${options.modules.exportOnlyLocals ? '' : `${importName}, `}* as ${importName}_NAMED___ from ${url};\n`;
385
+ } else {
386
+ code += `import ${importName} from ${url};\n`;
387
+ }
388
+ } else {
389
+ code += `var ${importName} = require(${url});\n`;
390
+ }
338
391
  }
339
392
 
340
393
  return code ? `// Imports\n${code}` : '';
341
394
  }
342
395
 
343
- function getModuleCode(result, api, replacements, options) {
396
+ function normalizeSourceMapForRuntime(map, loaderContext) {
397
+ const resultMap = map ? map.toJSON() : null;
398
+
399
+ if (resultMap) {
400
+ delete resultMap.file;
401
+ resultMap.sourceRoot = '';
402
+ resultMap.sources = resultMap.sources.map(source => {
403
+ // Non-standard syntax from `postcss`
404
+ if (source.indexOf('<') === 0) {
405
+ return source;
406
+ }
407
+
408
+ const sourceType = getURLType(source);
409
+
410
+ if (sourceType !== 'path-relative') {
411
+ return source;
412
+ }
413
+
414
+ const resourceDirname = _path.default.dirname(loaderContext.resourcePath);
415
+
416
+ const absoluteSource = _path.default.resolve(resourceDirname, source);
417
+
418
+ const contextifyPath = normalizePath(_path.default.relative(loaderContext.rootContext, absoluteSource));
419
+ return `webpack://${contextifyPath}`;
420
+ });
421
+ }
422
+
423
+ return JSON.stringify(resultMap);
424
+ }
425
+
426
+ function getModuleCode(result, api, replacements, options, loaderContext) {
344
427
  if (options.modules.exportOnlyLocals === true) {
345
- return 'var ___CSS_LOADER_EXPORT___ = {};\n';
428
+ return '';
346
429
  }
347
430
 
348
- const {
349
- css,
350
- map
351
- } = result;
352
- const sourceMapValue = options.sourceMap && map ? `,${map}` : '';
353
- let code = JSON.stringify(css);
431
+ const sourceMapValue = options.sourceMap ? `,${normalizeSourceMapForRuntime(result.map, loaderContext)}` : '';
432
+ let code = JSON.stringify(result.css);
354
433
  let beforeCode = `var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(${options.sourceMap});\n`;
355
434
 
356
435
  for (const item of api) {
@@ -391,7 +470,7 @@ function dashesCamelCase(str) {
391
470
  }
392
471
 
393
472
  function getExportCode(exports, replacements, options) {
394
- let code = '';
473
+ let code = '// Exports\n';
395
474
  let localsCode = '';
396
475
 
397
476
  const addExportToLocalsCode = (name, value) => {
@@ -464,18 +543,31 @@ function getExportCode(exports, replacements, options) {
464
543
  const {
465
544
  importName
466
545
  } = item;
467
- localsCode = localsCode.replace(new RegExp(replacementName, 'g'), () => options.modules.namedExport ? `" + ${importName}_NAMED___[${JSON.stringify((0, _camelcase.default)(localName))}] + "` : `" + ${importName}.locals[${JSON.stringify(localName)}] + "`);
546
+ localsCode = localsCode.replace(new RegExp(replacementName, 'g'), () => {
547
+ if (options.modules.namedExport) {
548
+ return `" + ${importName}_NAMED___[${JSON.stringify((0, _camelcase.default)(localName))}] + "`;
549
+ } else if (options.modules.exportOnlyLocals) {
550
+ return `" + ${importName}[${JSON.stringify(localName)}] + "`;
551
+ }
552
+
553
+ return `" + ${importName}.locals[${JSON.stringify(localName)}] + "`;
554
+ });
468
555
  } else {
469
556
  localsCode = localsCode.replace(new RegExp(replacementName, 'g'), () => `" + ${replacementName} + "`);
470
557
  }
471
558
  }
472
559
 
560
+ if (options.modules.exportOnlyLocals) {
561
+ code += options.modules.namedExport ? localsCode : `${options.esModule ? 'export default' : 'module.exports ='} {\n${localsCode}\n};\n`;
562
+ return code;
563
+ }
564
+
473
565
  if (localsCode) {
474
- code += options.modules.namedExport ? `${localsCode}` : `___CSS_LOADER_EXPORT___.locals = {\n${localsCode}\n};\n`;
566
+ code += options.modules.namedExport ? localsCode : `___CSS_LOADER_EXPORT___.locals = {\n${localsCode}\n};\n`;
475
567
  }
476
568
 
477
569
  code += `${options.esModule ? 'export default' : 'module.exports ='} ___CSS_LOADER_EXPORT___;\n`;
478
- return `// Exports\n${code}`;
570
+ return code;
479
571
  }
480
572
 
481
573
  async function resolveRequests(resolve, context, possibleRequests) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-loader",
3
- "version": "4.1.0",
3
+ "version": "4.2.2",
4
4
  "description": "css loader module for webpack",
5
5
  "license": "MIT",
6
6
  "repository": "webpack-contrib/css-loader",
@@ -47,7 +47,6 @@
47
47
  "cssesc": "^3.0.0",
48
48
  "icss-utils": "^4.1.1",
49
49
  "loader-utils": "^2.0.0",
50
- "normalize-path": "^3.0.0",
51
50
  "postcss": "^7.0.32",
52
51
  "postcss-modules-extract-imports": "^2.0.0",
53
52
  "postcss-modules-local-by-default": "^3.0.3",
@@ -59,10 +58,10 @@
59
58
  },
60
59
  "devDependencies": {
61
60
  "@babel/cli": "^7.10.5",
62
- "@babel/core": "^7.10.5",
61
+ "@babel/core": "^7.11.4",
63
62
  "@babel/preset-env": "^7.10.4",
64
- "@commitlint/cli": "^9.1.2",
65
- "@commitlint/config-conventional": "^9.1.1",
63
+ "@commitlint/cli": "^10.0.0",
64
+ "@commitlint/config-conventional": "^10.0.0",
66
65
  "@webpack-contrib/defaults": "^6.3.0",
67
66
  "@webpack-contrib/eslint-config-webpack": "^3.0.0",
68
67
  "babel-jest": "^26.1.0",
@@ -76,20 +75,23 @@
76
75
  "file-loader": "^6.0.0",
77
76
  "husky": "^4.2.5",
78
77
  "jest": "^26.1.0",
78
+ "less-loader": "^6.2.0",
79
79
  "lint-staged": "^10.2.11",
80
80
  "memfs": "^3.2.0",
81
- "mini-css-extract-plugin": "^0.9.0",
81
+ "mini-css-extract-plugin": "^0.10.0",
82
82
  "npm-run-all": "^4.1.5",
83
83
  "postcss-loader": "^3.0.0",
84
84
  "postcss-preset-env": "^6.7.0",
85
85
  "prettier": "^2.0.5",
86
86
  "sass": "^1.26.10",
87
87
  "sass-loader": "^9.0.2",
88
- "standard-version": "^8.0.2",
88
+ "standard-version": "^9.0.0",
89
89
  "strip-ansi": "^6.0.0",
90
90
  "style-loader": "^1.2.1",
91
+ "stylus": "^0.54.8",
92
+ "stylus-loader": "^3.0.2",
91
93
  "url-loader": "^4.1.0",
92
- "webpack": "^4.44.0"
94
+ "webpack": "^4.44.1"
93
95
  },
94
96
  "keywords": [
95
97
  "webpack",