css-loader 4.1.1 → 4.3.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,39 @@
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.3.0](https://github.com/webpack-contrib/css-loader/compare/v4.2.2...v4.3.0) (2020-09-08)
6
+
7
+
8
+ ### Features
9
+
10
+ * the `importLoaders` can be `string` ([#1178](https://github.com/webpack-contrib/css-loader/issues/1178)) ([ec58a7c](https://github.com/webpack-contrib/css-loader/commit/ec58a7cfda46443e35539d66b86685195fa5db03))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * line breaks in `url` function ([88b8ddc](https://github.com/webpack-contrib/css-loader/commit/88b8ddc1d78a2b6a917ed2dfe2f2a37cf6a84190))
16
+
17
+ ### [4.2.2](https://github.com/webpack-contrib/css-loader/compare/v4.2.1...v4.2.2) (2020-08-24)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * 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))
23
+
24
+ ### [4.2.1](https://github.com/webpack-contrib/css-loader/compare/v4.2.0...v4.2.1) (2020-08-06)
25
+
26
+
27
+ ### Bug Fixes
28
+
29
+ * 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))
30
+
31
+ ## [4.2.0](https://github.com/webpack-contrib/css-loader/compare/v4.1.1...v4.2.0) (2020-07-31)
32
+
33
+
34
+ ### Features
35
+
36
+ * 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))
37
+
5
38
  ### [4.1.1](https://github.com/webpack-contrib/css-loader/compare/v4.1.0...v4.1.1) (2020-07-30)
6
39
 
7
40
 
package/README.md CHANGED
@@ -109,15 +109,14 @@ module.exports = {
109
109
 
110
110
  ## Options
111
111
 
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}` | `{auto: true}` | Enables/Disables CSS Modules and their configuration |
117
- | **[`icss`](#icss)** | `{Boolean}` | `true` if `modules` are enabled, `false` otherwise | Enables/Disables Interoperable CSS |
118
- | **[`sourceMap`](#sourcemap)** | `{Boolean}` | `compiler.devtool` | Enables/Disables generation of source maps |
119
- | **[`importLoaders`](#importloaders)** | `{Number}` | `0` | Enables/Disables or setups number of loaders applied before CSS loader |
120
- | **[`esModule`](#esmodule)** | `{Boolean}` | `true` | Use ES modules syntax |
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}` | `{auto: true}` | Enables/Disables CSS Modules and their configuration |
117
+ | **[`sourceMap`](#sourcemap)** | `{Boolean}` | `compiler.devtool` | Enables/Disables generation of source maps |
118
+ | **[`importLoaders`](#importloaders)** | `{Number}` | `0` | Enables/Disables or setups number of loaders applied before CSS loader |
119
+ | **[`esModule`](#esmodule)** | `{Boolean}` | `true` | Use ES modules syntax |
121
120
 
122
121
  ### `url`
123
122
 
@@ -526,6 +525,7 @@ module.exports = {
526
525
  loader: 'css-loader',
527
526
  options: {
528
527
  modules: {
528
+ compileType: 'module',
529
529
  mode: 'local',
530
530
  auto: true,
531
531
  exportGlobals: true,
@@ -543,6 +543,38 @@ module.exports = {
543
543
  };
544
544
  ```
545
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
+
546
578
  ##### `auto`
547
579
 
548
580
  Type: `Boolean|RegExp|Function`
@@ -919,7 +951,7 @@ module.exports = {
919
951
  };
920
952
  ```
921
953
 
922
- ##### `exportlocalsConvention`
954
+ ##### `exportLocalsConvention`
923
955
 
924
956
  Type: `String`
925
957
  Default: based on the `modules.namedExport` option value, if `true` - `camelCaseOnly`, otherwise `asIs`
@@ -1001,33 +1033,6 @@ module.exports = {
1001
1033
  };
1002
1034
  ```
1003
1035
 
1004
- ### `icss`
1005
-
1006
- Type: Boolean Default: `true` if `modules` are enabled, false otherwise
1007
-
1008
- Enables/disables handling of the low level "Interoperable CSS" format for declaring
1009
- import and export dependencies between CSS and other languages. ICSS enables
1010
- CSS Module support, and is enabled automatically when `modules` are enabled. It
1011
- can also be enabled independently to allow other loaders to handle processing CSS modules.
1012
-
1013
- **webpack.config.js**
1014
-
1015
- ```js
1016
- module.exports = {
1017
- module: {
1018
- rules: [
1019
- {
1020
- test: /\.css$/i,
1021
- loader: 'css-loader',
1022
- options: {
1023
- icss: true,
1024
- },
1025
- },
1026
- ],
1027
- },
1028
- };
1029
- ```
1030
-
1031
1036
  ### `sourceMap`
1032
1037
 
1033
1038
  Type: `Boolean`
@@ -1238,6 +1243,111 @@ module.exports = {
1238
1243
  };
1239
1244
  ```
1240
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
+
1241
1351
  ## Contributing
1242
1352
 
1243
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": [
@@ -132,6 +136,9 @@
132
136
  {
133
137
  "type": "boolean"
134
138
  },
139
+ {
140
+ "type": "string"
141
+ },
135
142
  {
136
143
  "type": "integer"
137
144
  }
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
@@ -94,8 +97,8 @@ function defaultGetLocalIdent(loaderContext, localIdentName, localName, options)
94
97
  function normalizeUrl(url, isStringValue) {
95
98
  let normalizedUrl = url;
96
99
 
97
- if (isStringValue && /\\[\n]/.test(normalizedUrl)) {
98
- normalizedUrl = normalizedUrl.replace(/\\[\n]/g, '');
100
+ if (isStringValue && /\\(\n|\r\n|\r|\f)/.test(normalizedUrl)) {
101
+ normalizedUrl = normalizedUrl.replace(/\\(\n|\r\n|\r|\f)/g, '');
99
102
  }
100
103
 
101
104
  if (matchNativeWin32Path.test(url)) {
@@ -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,14 +211,19 @@ 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
- importLoaders: rawOptions.importLoaders,
226
+ importLoaders: typeof rawOptions.importLoaders === 'string' ? parseInt(rawOptions.importLoaders, 10) : rawOptions.importLoaders,
218
227
  esModule: typeof rawOptions.esModule === 'undefined' ? true : rawOptions.esModule
219
228
  };
220
229
  }
@@ -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.1",
3
+ "version": "4.3.0",
4
4
  "description": "css loader module for webpack",
5
5
  "license": "MIT",
6
6
  "repository": "webpack-contrib/css-loader",
@@ -47,22 +47,21 @@
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",
54
53
  "postcss-modules-scope": "^2.2.0",
55
54
  "postcss-modules-values": "^3.0.0",
56
55
  "postcss-value-parser": "^4.1.0",
57
- "schema-utils": "^2.7.0",
56
+ "schema-utils": "^2.7.1",
58
57
  "semver": "^7.3.2"
59
58
  },
60
59
  "devDependencies": {
61
- "@babel/cli": "^7.10.5",
62
- "@babel/core": "^7.10.5",
63
- "@babel/preset-env": "^7.10.4",
64
- "@commitlint/cli": "^9.1.2",
65
- "@commitlint/config-conventional": "^9.1.1",
60
+ "@babel/cli": "^7.11.6",
61
+ "@babel/core": "^7.11.6",
62
+ "@babel/preset-env": "^7.11.5",
63
+ "@commitlint/cli": "^11.0.0",
64
+ "@commitlint/config-conventional": "^11.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",
@@ -70,26 +69,30 @@
70
69
  "del": "^5.1.0",
71
70
  "del-cli": "^3.0.1",
72
71
  "es-check": "^5.1.0",
73
- "eslint": "^7.5.0",
72
+ "eslint": "^7.8.1",
74
73
  "eslint-config-prettier": "^6.11.0",
75
74
  "eslint-plugin-import": "^2.22.0",
76
- "file-loader": "^6.0.0",
77
- "husky": "^4.2.5",
78
- "jest": "^26.1.0",
79
- "lint-staged": "^10.2.11",
75
+ "file-loader": "^6.1.0",
76
+ "husky": "^4.3.0",
77
+ "jest": "^26.4.2",
78
+ "less": "^3.12.2",
79
+ "less-loader": "^7.0.1",
80
+ "lint-staged": "^10.3.0",
80
81
  "memfs": "^3.2.0",
81
- "mini-css-extract-plugin": "^0.9.0",
82
+ "mini-css-extract-plugin": "^0.11.0",
82
83
  "npm-run-all": "^4.1.5",
83
- "postcss-loader": "^3.0.0",
84
+ "postcss-loader": "^4.0.0",
84
85
  "postcss-preset-env": "^6.7.0",
85
- "prettier": "^2.0.5",
86
+ "prettier": "^2.1.1",
86
87
  "sass": "^1.26.10",
87
- "sass-loader": "^9.0.2",
88
- "standard-version": "^8.0.2",
88
+ "sass-loader": "^10.0.2",
89
+ "standard-version": "^9.0.0",
89
90
  "strip-ansi": "^6.0.0",
90
91
  "style-loader": "^1.2.1",
92
+ "stylus": "^0.54.8",
93
+ "stylus-loader": "^3.0.2",
91
94
  "url-loader": "^4.1.0",
92
- "webpack": "^4.44.0"
95
+ "webpack": "^4.44.1"
93
96
  },
94
97
  "keywords": [
95
98
  "webpack",