sass-loader 11.1.1 → 12.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/README.md CHANGED
@@ -119,17 +119,18 @@ Thankfully there are a two solutions to this problem:
119
119
 
120
120
  ## Options
121
121
 
122
- | Name | Type | Default | Description |
123
- | :---------------------------------------: | :------------------: | :-------------------------------------: | :---------------------------------------------------------------- |
124
- | **[`implementation`](#implementation)** | `{Object}` | `sass` | Setup Sass implementation to use. |
125
- | **[`sassOptions`](#sassoptions)** | `{Object\|Function}` | defaults values for Sass implementation | Options for Sass. |
126
- | **[`sourceMap`](#sourcemap)** | `{Boolean}` | `compiler.devtool` | Enables/Disables generation of source maps. |
127
- | **[`additionalData`](#additionaldata)** | `{String\|Function}` | `undefined` | Prepends/Appends `Sass`/`SCSS` code before the actual entry file. |
128
- | **[`webpackImporter`](#webpackimporter)** | `{Boolean}` | `true` | Enables/Disables the default Webpack importer. |
122
+ | Name | Type | Default | Description |
123
+ | :-------------------------------------------: | :------------------: | :-------------------------------------: | :---------------------------------------------------------------- |
124
+ | **[`implementation`](#implementation)** | `{Object\|String}` | `sass` | Setup Sass implementation to use. |
125
+ | **[`sassOptions`](#sassoptions)** | `{Object\|Function}` | defaults values for Sass implementation | Options for Sass. |
126
+ | **[`sourceMap`](#sourcemap)** | `{Boolean}` | `compiler.devtool` | Enables/Disables generation of source maps. |
127
+ | **[`additionalData`](#additionaldata)** | `{String\|Function}` | `undefined` | Prepends/Appends `Sass`/`SCSS` code before the actual entry file. |
128
+ | **[`webpackImporter`](#webpackimporter)** | `{Boolean}` | `true` | Enables/Disables the default Webpack importer. |
129
+ | **[`warnRuleAsWarning`](#warnruleaswarning)** | `{Boolean}` | `false` | Treats the `@warn` rule as a webpack warning. |
129
130
 
130
131
  ### `implementation`
131
132
 
132
- Type: `Object`
133
+ Type: `Object | String`
133
134
  Default: `sass`
134
135
 
135
136
  The special `implementation` option determines which implementation of Sass to use.
@@ -168,6 +169,8 @@ In order to avoid this situation you can use the `implementation` option.
168
169
 
169
170
  The `implementation` options either accepts `sass` (`Dart Sass`) or `node-sass` as a module.
170
171
 
172
+ #### Object
173
+
171
174
  For example, to use Dart Sass, you'd pass:
172
175
 
173
176
  ```js
@@ -193,6 +196,33 @@ module.exports = {
193
196
  };
194
197
  ```
195
198
 
199
+ #### String
200
+
201
+ For example, to use Dart Sass, you'd pass:
202
+
203
+ ```js
204
+ module.exports = {
205
+ module: {
206
+ rules: [
207
+ {
208
+ test: /\.s[ac]ss$/i,
209
+ use: [
210
+ "style-loader",
211
+ "css-loader",
212
+ {
213
+ loader: "sass-loader",
214
+ options: {
215
+ // Prefer `dart-sass`
216
+ implementation: require.resolve("sass"),
217
+ },
218
+ },
219
+ ],
220
+ },
221
+ ],
222
+ },
223
+ };
224
+ ```
225
+
196
226
  Note that when using `sass` (`Dart Sass`), **synchronous compilation is twice as fast as asynchronous compilation** by default, due to the overhead of asynchronous callbacks.
197
227
  To avoid this overhead, you can use the [fibers](https://www.npmjs.com/package/fibers) package to call asynchronous importers from the synchronous code path.
198
228
 
@@ -277,11 +307,13 @@ Default: defaults values for Sass implementation
277
307
 
278
308
  Options for [Dart Sass](http://sass-lang.com/dart-sass) or [Node Sass](https://github.com/sass/node-sass) implementation.
279
309
 
310
+ > ℹ️ The `charset` option has `true` value by default for `dart-sass`, we strongly discourage change value to `false`, because webpack doesn't support files other than `utf-8`.
311
+
280
312
  > ℹ️ The `indentedSyntax` option has `true` value for the `sass` extension.
281
313
 
282
314
  > ℹ️ Options such as `data` and `file` are unavailable and will be ignored.
283
315
 
284
- > ℹ We recommend not to set the `outFile`, `sourceMapContents`, `sourceMapEmbed`, `sourceMapRoot` options because `sass-loader` automatically sets these options when the `sourceMap` option is `true`.
316
+ > ℹ We strongly discourage change `outFile`, `sourceMapContents`, `sourceMapEmbed`, `sourceMapRoot` options because `sass-loader` automatically sets these options when the `sourceMap` option is `true`.
285
317
 
286
318
  > ℹ️ Access to the [loader context](https://webpack.js.org/api/loaders/#the-loader-context) inside the custom importer can be done using the `this.webpackLoaderContext` property.
287
319
 
@@ -573,6 +605,65 @@ module.exports = {
573
605
  };
574
606
  ```
575
607
 
608
+ ### `warnRuleAsWarning`
609
+
610
+ Type: `Boolean`
611
+ Default: `false`
612
+
613
+ Treats the `@warn` rule as a webpack warning.
614
+
615
+ > ℹ️ It will be `true` by default in the next major release.
616
+
617
+ **style.scss**
618
+
619
+ ```scss
620
+ $known-prefixes: webkit, moz, ms, o;
621
+
622
+ @mixin prefix($property, $value, $prefixes) {
623
+ @each $prefix in $prefixes {
624
+ @if not index($known-prefixes, $prefix) {
625
+ @warn "Unknown prefix #{$prefix}.";
626
+ }
627
+
628
+ -#{$prefix}-#{$property}: $value;
629
+ }
630
+ #{$property}: $value;
631
+ }
632
+
633
+ .tilt {
634
+ // Oops, we typo'd "webkit" as "wekbit"!
635
+ @include prefix(transform, rotate(15deg), wekbit ms);
636
+ }
637
+ ```
638
+
639
+ The presented code will throw webpack warning instead logging.
640
+
641
+ To ignore unnecessary warnings you can use the [ignoreWarnings](https://webpack.js.org/configuration/other-options/#ignorewarnings) option.
642
+
643
+ **webpack.config.js**
644
+
645
+ ```js
646
+ module.exports = {
647
+ module: {
648
+ rules: [
649
+ {
650
+ test: /\.s[ac]ss$/i,
651
+ use: [
652
+ "style-loader",
653
+ "css-loader",
654
+ {
655
+ loader: "sass-loader",
656
+ options: {
657
+ warnRuleAsWarning: true,
658
+ },
659
+ },
660
+ ],
661
+ },
662
+ ],
663
+ },
664
+ };
665
+ ```
666
+
576
667
  ## Examples
577
668
 
578
669
  ### Extracts CSS into separate files
package/dist/SassError.js CHANGED
@@ -8,7 +8,8 @@ exports.default = void 0;
8
8
  class SassError extends Error {
9
9
  constructor(sassError) {
10
10
  super();
11
- this.name = "SassError";
11
+ this.name = "SassError"; // TODO remove me in the next major release
12
+
12
13
  this.originalSassError = sassError;
13
14
  this.loc = {
14
15
  line: sassError.line,
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ class SassWarning extends Error {
9
+ constructor(warning, options) {
10
+ super(warning);
11
+ this.name = "SassWarning";
12
+ this.hideStack = true;
13
+
14
+ if (options.span) {
15
+ this.loc = {
16
+ line: options.span.start.line,
17
+ column: options.span.start.column
18
+ };
19
+ }
20
+ }
21
+
22
+ }
23
+
24
+ var _default = SassWarning;
25
+ exports.default = _default;
package/dist/options.json CHANGED
@@ -3,11 +3,20 @@
3
3
  "type": "object",
4
4
  "properties": {
5
5
  "implementation": {
6
- "description": "The implementation of the sass to be used (https://github.com/webpack-contrib/sass-loader#implementation).",
7
- "type": "object"
6
+ "description": "The implementation of the sass to be used.",
7
+ "link": "https://github.com/webpack-contrib/sass-loader#implementation",
8
+ "anyOf": [
9
+ {
10
+ "type": "string"
11
+ },
12
+ {
13
+ "type": "object"
14
+ }
15
+ ]
8
16
  },
9
17
  "sassOptions": {
10
- "description": "Options for `node-sass` or `sass` (`Dart Sass`) implementation. (https://github.com/webpack-contrib/sass-loader#implementation).",
18
+ "description": "Options for `node-sass` or `sass` (`Dart Sass`) implementation.",
19
+ "link": "https://github.com/webpack-contrib/sass-loader#sassoptions",
11
20
  "anyOf": [
12
21
  {
13
22
  "type": "object",
@@ -19,7 +28,8 @@
19
28
  ]
20
29
  },
21
30
  "additionalData": {
22
- "description": "Prepends/Appends `Sass`/`SCSS` code before the actual entry file (https://github.com/webpack-contrib/sass-loader#additionaldata).",
31
+ "description": "Prepends/Appends `Sass`/`SCSS` code before the actual entry file.",
32
+ "link": "https://github.com/webpack-contrib/sass-loader#additionaldata",
23
33
  "anyOf": [
24
34
  {
25
35
  "type": "string"
@@ -30,11 +40,18 @@
30
40
  ]
31
41
  },
32
42
  "sourceMap": {
33
- "description": "Enables/Disables generation of source maps (https://github.com/webpack-contrib/sass-loader#sourcemap).",
43
+ "description": "Enables/Disables generation of source maps.",
44
+ "link": "https://github.com/webpack-contrib/sass-loader#sourcemap",
34
45
  "type": "boolean"
35
46
  },
36
47
  "webpackImporter": {
37
- "description": "Enables/Disables default `webpack` importer (https://github.com/webpack-contrib/sass-loader#webpackimporter).",
48
+ "description": "Enables/Disables default `webpack` importer.",
49
+ "link": "https://github.com/webpack-contrib/sass-loader#webpackimporter",
50
+ "type": "boolean"
51
+ },
52
+ "warnRuleAsWarning": {
53
+ "description": "Treats the '@warn' rule as a webpack warning.",
54
+ "link": "https://github.com/webpack-contrib/sass-loader#warnruleaswarning",
38
55
  "type": "boolean"
39
56
  }
40
57
  },
package/dist/utils.js CHANGED
@@ -3,13 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.getRenderFunctionFromSassImplementation = getRenderFunctionFromSassImplementation;
6
7
  exports.getSassImplementation = getSassImplementation;
7
8
  exports.getSassOptions = getSassOptions;
8
- exports.getWebpackResolver = getWebpackResolver;
9
9
  exports.getWebpackImporter = getWebpackImporter;
10
- exports.getRenderFunctionFromSassImplementation = getRenderFunctionFromSassImplementation;
11
- exports.normalizeSourceMap = normalizeSourceMap;
10
+ exports.getWebpackResolver = getWebpackResolver;
12
11
  exports.isSupportedFibers = isSupportedFibers;
12
+ exports.normalizeSourceMap = normalizeSourceMap;
13
13
 
14
14
  var _url = _interopRequireDefault(require("url"));
15
15
 
@@ -19,6 +19,8 @@ var _full = require("klona/full");
19
19
 
20
20
  var _neoAsync = _interopRequireDefault(require("neo-async"));
21
21
 
22
+ var _SassWarning = _interopRequireDefault(require("./SassWarning"));
23
+
22
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
25
 
24
26
  function getDefaultSassImplementation() {
@@ -40,9 +42,7 @@ function getDefaultSassImplementation() {
40
42
  return require(sassImplPkg);
41
43
  }
42
44
  /**
43
- * @public
44
- * This function is not Webpack-specific and can be used by tools wishing to
45
- * mimic `sass-loader`'s behaviour, so its signature should not be changed.
45
+ * This function is not Webpack-specific and can be used by tools wishing to mimic `sass-loader`'s behaviour, so its signature should not be changed.
46
46
  */
47
47
 
48
48
 
@@ -58,6 +58,17 @@ function getSassImplementation(loaderContext, implementation) {
58
58
  }
59
59
  }
60
60
 
61
+ if (typeof resolvedImplementation === "string") {
62
+ try {
63
+ // eslint-disable-next-line import/no-dynamic-require, global-require
64
+ resolvedImplementation = require(resolvedImplementation);
65
+ } catch (error) {
66
+ loaderContext.emitError(error); // eslint-disable-next-line consistent-return
67
+
68
+ return;
69
+ }
70
+ }
71
+
61
72
  const {
62
73
  info
63
74
  } = resolvedImplementation;
@@ -86,6 +97,11 @@ function getSassImplementation(loaderContext, implementation) {
86
97
 
87
98
  loaderContext.emitError(new Error(`Unknown Sass implementation "${implementationName}".`));
88
99
  }
100
+ /**
101
+ * @param {any} loaderContext
102
+ * @returns {boolean}
103
+ */
104
+
89
105
 
90
106
  function isProductionLikeMode(loaderContext) {
91
107
  return loaderContext.mode === "production" || !loaderContext.mode;
@@ -93,8 +109,10 @@ function isProductionLikeMode(loaderContext) {
93
109
 
94
110
  function proxyCustomImporters(importers, loaderContext) {
95
111
  return [].concat(importers).map(importer => function proxyImporter(...args) {
96
- this.webpackLoaderContext = loaderContext;
97
- return importer.apply(this, args);
112
+ const self = { ...this,
113
+ webpackLoaderContext: loaderContext
114
+ };
115
+ return importer.apply(self, args);
98
116
  });
99
117
  }
100
118
 
@@ -180,6 +198,57 @@ async function getSassOptions(loaderContext, loaderOptions, content, implementat
180
198
  options.importer = options.importer ? proxyCustomImporters(Array.isArray(options.importer) ? options.importer : [options.importer], loaderContext) : [];
181
199
  options.includePaths = [].concat(process.cwd()).concat( // We use `includePaths` in context for resolver, so it should be always absolute
182
200
  (options.includePaths || []).map(includePath => _path.default.isAbsolute(includePath) ? includePath : _path.default.join(process.cwd(), includePath))).concat(process.env.SASS_PATH ? process.env.SASS_PATH.split(process.platform === "win32" ? ";" : ":") : []);
201
+
202
+ if (typeof options.charset === "undefined") {
203
+ options.charset = true;
204
+ }
205
+
206
+ if (!options.logger) {
207
+ // TODO set me to `true` by default in the next major release
208
+ const needEmitWarning = loaderOptions.warnRuleAsWarning === true;
209
+ const logger = loaderContext.getLogger("sass-loader");
210
+
211
+ const formatSpan = span => `${span.url || "-"}:${span.start.line}:${span.start.column}: `;
212
+
213
+ options.logger = {
214
+ debug(message, loggerOptions) {
215
+ let builtMessage = "";
216
+
217
+ if (loggerOptions.span) {
218
+ builtMessage = formatSpan(loggerOptions.span);
219
+ }
220
+
221
+ builtMessage += message;
222
+ logger.debug(builtMessage);
223
+ },
224
+
225
+ warn(message, loggerOptions) {
226
+ let builtMessage = "";
227
+
228
+ if (loggerOptions.deprecation) {
229
+ builtMessage += "Deprecation ";
230
+ }
231
+
232
+ if (loggerOptions.span && !loggerOptions.stack) {
233
+ builtMessage = formatSpan(loggerOptions.span);
234
+ }
235
+
236
+ builtMessage += message;
237
+
238
+ if (loggerOptions.stack) {
239
+ builtMessage += `\n\n${loggerOptions.stack}`;
240
+ }
241
+
242
+ if (needEmitWarning) {
243
+ loaderContext.emitWarning(new _SassWarning.default(builtMessage, loggerOptions));
244
+ } else {
245
+ logger.warn(builtMessage);
246
+ }
247
+ }
248
+
249
+ };
250
+ }
251
+
183
252
  return options;
184
253
  }
185
254
 
@@ -203,12 +272,12 @@ const IS_MODULE_IMPORT = /^~([^/]+|[^/]+\/|@[^/]+[/][^/]+|@[^/]+\/?|@[^/]+[/][^/
203
272
  *
204
273
  * @param {string} url
205
274
  * @param {boolean} forWebpackResolver
206
- * @param {string} rootContext
275
+ * @param {boolean} fromImport
207
276
  * @returns {Array<string>}
208
277
  */
209
278
 
210
279
  function getPossibleRequests( // eslint-disable-next-line no-shadow
211
- url, forWebpackResolver = false) {
280
+ url, forWebpackResolver = false, fromImport = false) {
212
281
  let request = url; // In case there is module request, send this to webpack resolver
213
282
 
214
283
  if (forWebpackResolver) {
@@ -224,7 +293,7 @@ url, forWebpackResolver = false) {
224
293
  // @see https://github.com/webpack-contrib/sass-loader/issues/167
225
294
 
226
295
 
227
- const ext = _path.default.extname(request).toLowerCase(); // Because @import is also defined in CSS, Sass needs a way of compiling plain CSS @imports without trying to import the files at compile time.
296
+ const extension = _path.default.extname(request).toLowerCase(); // Because @import is also defined in CSS, Sass needs a way of compiling plain CSS @imports without trying to import the files at compile time.
228
297
  // To accomplish this, and to ensure SCSS is as much of a superset of CSS as possible, Sass will compile any @imports with the following characteristics to plain CSS imports:
229
298
  // - imports where the URL ends with .css.
230
299
  // - imports where the URL begins http:// or https://.
@@ -234,15 +303,19 @@ url, forWebpackResolver = false) {
234
303
  // The `node-sass` package sends `@import` ending on `.css` to importer, it is bug, so we skip resolve
235
304
 
236
305
 
237
- if (ext === ".css") {
306
+ if (extension === ".css") {
238
307
  return [];
239
308
  }
240
309
 
241
310
  const dirname = _path.default.dirname(request);
242
311
 
312
+ const normalizedDirname = dirname === "." ? "" : `${dirname}/`;
313
+
243
314
  const basename = _path.default.basename(request);
244
315
 
245
- return [...new Set([`${dirname}/_${basename}`, request].concat(forWebpackResolver ? [`${_path.default.dirname(url)}/_${basename}`, url] : []))];
316
+ const basenameWithoutExtension = _path.default.basename(request, extension);
317
+
318
+ return [...new Set([].concat(fromImport ? [`${normalizedDirname}_${basenameWithoutExtension}.import${extension}`, `${normalizedDirname}${basenameWithoutExtension}.import${extension}`] : []).concat([`${normalizedDirname}_${basename}`, `${normalizedDirname}${basename}`]).concat(forWebpackResolver ? [url] : []))];
246
319
  }
247
320
 
248
321
  function promiseResolve(callbackResolve) {
@@ -313,8 +386,16 @@ function getWebpackResolver(resolverFactory, implementation, includePaths = [])
313
386
  }
314
387
  }
315
388
 
316
- const isDartSass = implementation.info.includes("dart-sass");
317
- const sassResolve = promiseResolve(resolverFactory({
389
+ const isDartSass = implementation.info.includes("dart-sass"); // We only have one difference with the built-in sass resolution logic and out resolution logic:
390
+ // First, we look at the files starting with `_`, then without `_` (i.e. `_name.sass`, `_name.scss`, `_name.css`, `name.sass`, `name.scss`, `name.css`),
391
+ // although `sass` look together by extensions (i.e. `_name.sass`/`name.sass`/`_name.scss`/`name.scss`/`_name.css`/`name.css`).
392
+ // It shouldn't be a problem because `sass` throw errors:
393
+ // - on having `_name.sass` and `name.sass` (extension can be `sass`, `scss` or `css`) in the same directory
394
+ // - on having `_name.sass` and `_name.scss` in the same directory
395
+ //
396
+ // Also `sass` prefer `sass`/`scss` over `css`.
397
+
398
+ const sassModuleResolve = promiseResolve(resolverFactory({
318
399
  alias: [],
319
400
  aliasFields: [],
320
401
  conditionNames: [],
@@ -327,7 +408,20 @@ function getWebpackResolver(resolverFactory, implementation, includePaths = [])
327
408
  restrictions: [/\.((sa|sc|c)ss)$/i],
328
409
  preferRelative: true
329
410
  }));
330
- const webpackResolve = promiseResolve(resolverFactory({
411
+ const sassImportResolve = promiseResolve(resolverFactory({
412
+ alias: [],
413
+ aliasFields: [],
414
+ conditionNames: [],
415
+ descriptionFiles: [],
416
+ extensions: [".sass", ".scss", ".css"],
417
+ exportsFields: [],
418
+ mainFields: [],
419
+ mainFiles: ["_index.import", "_index", "index.import", "index"],
420
+ modules: [],
421
+ restrictions: [/\.((sa|sc|c)ss)$/i],
422
+ preferRelative: true
423
+ }));
424
+ const webpackModuleResolve = promiseResolve(resolverFactory({
331
425
  dependencyType: "sass",
332
426
  conditionNames: ["sass", "style"],
333
427
  mainFields: ["sass", "style", "main", "..."],
@@ -336,7 +430,16 @@ function getWebpackResolver(resolverFactory, implementation, includePaths = [])
336
430
  restrictions: [/\.((sa|sc|c)ss)$/i],
337
431
  preferRelative: true
338
432
  }));
339
- return (context, request) => {
433
+ const webpackImportResolve = promiseResolve(resolverFactory({
434
+ dependencyType: "sass",
435
+ conditionNames: ["sass", "style"],
436
+ mainFields: ["sass", "style", "main", "..."],
437
+ mainFiles: ["_index.import", "_index", "index.import", "index", "..."],
438
+ extensions: [".sass", ".scss", ".css"],
439
+ restrictions: [/\.((sa|sc|c)ss)$/i],
440
+ preferRelative: true
441
+ }));
442
+ return (context, request, fromImport) => {
340
443
  // See https://github.com/webpack/webpack/issues/12340
341
444
  // Because `node-sass` calls our importer before `1. Filesystem imports relative to the base file.`
342
445
  // custom importer may not return `{ file: '/path/to/name.ext' }` and therefore our `context` will be relative
@@ -375,11 +478,11 @@ function getWebpackResolver(resolverFactory, implementation, includePaths = [])
375
478
  // 5. Filesystem imports relative to a `SASS_PATH` path.
376
479
  //
377
480
  // `sass` run custom importers before `3`, `4` and `5` points, we need to emulate this behavior to avoid wrong resolution.
378
- const sassPossibleRequests = getPossibleRequests(request); // `node-sass` calls our importer before `1. Filesystem imports relative to the base file.`, so we need emulate this too
481
+ const sassPossibleRequests = getPossibleRequests(request, false, fromImport); // `node-sass` calls our importer before `1. Filesystem imports relative to the base file.`, so we need emulate this too
379
482
 
380
483
  if (!isDartSass) {
381
484
  resolutionMap = resolutionMap.concat({
382
- resolve: sassResolve,
485
+ resolve: fromImport ? sassImportResolve : sassModuleResolve,
383
486
  context: _path.default.dirname(context),
384
487
  possibleRequests: sassPossibleRequests
385
488
  });
@@ -388,16 +491,16 @@ function getWebpackResolver(resolverFactory, implementation, includePaths = [])
388
491
  resolutionMap = resolutionMap.concat( // eslint-disable-next-line no-shadow
389
492
  includePaths.map(context => {
390
493
  return {
391
- resolve: sassResolve,
494
+ resolve: fromImport ? sassImportResolve : sassModuleResolve,
392
495
  context,
393
496
  possibleRequests: sassPossibleRequests
394
497
  };
395
498
  }));
396
499
  }
397
500
 
398
- const webpackPossibleRequests = getPossibleRequests(request, true);
501
+ const webpackPossibleRequests = getPossibleRequests(request, true, fromImport);
399
502
  resolutionMap = resolutionMap.concat({
400
- resolve: webpackResolve,
503
+ resolve: fromImport ? webpackImportResolve : webpackModuleResolve,
401
504
  context: _path.default.dirname(context),
402
505
  possibleRequests: webpackPossibleRequests
403
506
  });
@@ -405,19 +508,22 @@ function getWebpackResolver(resolverFactory, implementation, includePaths = [])
405
508
  };
406
509
  }
407
510
 
408
- const matchCss = /\.css$/i;
511
+ const MATCH_CSS = /\.css$/i;
409
512
 
410
513
  function getWebpackImporter(loaderContext, implementation, includePaths) {
411
514
  const resolve = getWebpackResolver(loaderContext.getResolve, implementation, includePaths);
412
- return (originalUrl, prev, done) => {
413
- resolve(prev, originalUrl).then(result => {
515
+ return function importer(originalUrl, prev, done) {
516
+ const {
517
+ fromImport
518
+ } = this;
519
+ resolve(prev, originalUrl, fromImport).then(result => {
414
520
  // Add the result as dependency.
415
521
  // Although we're also using stats.includedFiles, this might come in handy when an error occurs.
416
522
  // In this case, we don't get stats.includedFiles from node-sass/sass.
417
523
  loaderContext.addDependency(_path.default.normalize(result)); // By removing the CSS file extension, we trigger node-sass to include the CSS file instead of just linking it.
418
524
 
419
525
  done({
420
- file: result.replace(matchCss, "")
526
+ file: result.replace(MATCH_CSS, "")
421
527
  });
422
528
  }) // Catch all resolving errors, return the original file and pass responsibility back to other custom importers
423
529
  .catch(() => {
@@ -455,6 +561,10 @@ function getRenderFunctionFromSassImplementation(implementation) {
455
561
  }
456
562
 
457
563
  const ABSOLUTE_SCHEME = /^[A-Za-z0-9+\-.]+:/;
564
+ /**
565
+ * @param {string} source
566
+ * @returns {"absolute" | "scheme-relative" | "path-absolute" | "path-absolute"}
567
+ */
458
568
 
459
569
  function getURLType(source) {
460
570
  if (source[0] === "/") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sass-loader",
3
- "version": "11.1.1",
3
+ "version": "12.3.0",
4
4
  "description": "Sass loader for webpack",
5
5
  "license": "MIT",
6
6
  "repository": "webpack-contrib/sass-loader",
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "main": "dist/cjs.js",
15
15
  "engines": {
16
- "node": ">= 10.13.0"
16
+ "node": ">= 12.13.0"
17
17
  },
18
18
  "scripts": {
19
19
  "start": "npm run build -- -w",
@@ -21,7 +21,7 @@
21
21
  "prebuild": "npm run clean",
22
22
  "build": "cross-env NODE_ENV=production babel src -d dist --copy-files",
23
23
  "commitlint": "commitlint --from=master",
24
- "security": "npm audit",
24
+ "security": "npm audit --production",
25
25
  "lint:prettier": "prettier --list-different .",
26
26
  "lint:js": "eslint --cache .",
27
27
  "lint": "npm-run-all -l -p \"lint:**\"",
@@ -59,40 +59,41 @@
59
59
  "neo-async": "^2.6.2"
60
60
  },
61
61
  "devDependencies": {
62
- "@babel/cli": "^7.13.16",
63
- "@babel/core": "^7.14.0",
64
- "@babel/preset-env": "^7.14.1",
65
- "@commitlint/cli": "^12.1.1",
66
- "@commitlint/config-conventional": "^12.1.1",
62
+ "@babel/cli": "^7.14.5",
63
+ "@babel/core": "^7.14.6",
64
+ "@babel/preset-env": "^7.14.7",
65
+ "@commitlint/cli": "^13.1.0",
66
+ "@commitlint/config-conventional": "^13.1.0",
67
67
  "@webpack-contrib/eslint-config-webpack": "^3.0.0",
68
- "babel-jest": "^26.6.3",
69
- "bootstrap": "^4.5.3",
68
+ "babel-jest": "^27.0.6",
70
69
  "bootstrap-sass": "^3.4.1",
70
+ "bootstrap-v4": "npm:bootstrap@^4.5.3",
71
+ "bootstrap-v5": "npm:bootstrap@^5.0.1",
71
72
  "cross-env": "^7.0.3",
72
- "css-loader": "^5.2.4",
73
+ "css-loader": "^6.2.0",
73
74
  "del": "^6.0.0",
74
- "del-cli": "^3.0.1",
75
- "enhanced-resolve": "^5.8.0",
76
- "eslint": "^7.26.0",
75
+ "del-cli": "^4.0.1",
76
+ "enhanced-resolve": "^5.8.2",
77
+ "eslint": "^8.1.0",
77
78
  "eslint-config-prettier": "^8.3.0",
78
- "eslint-plugin-import": "^2.22.1",
79
+ "eslint-plugin-import": "^2.23.3",
79
80
  "fibers": "^5.0.0",
80
81
  "file-loader": "^6.2.0",
81
82
  "foundation-sites": "^6.6.3",
82
- "husky": "^6.0.0",
83
- "jest": "^26.6.3",
84
- "lint-staged": "^11.0.0",
83
+ "husky": "^7.0.1",
84
+ "jest": "^27.0.6",
85
+ "lint-staged": "^11.0.1",
85
86
  "material-components-web": "^8.0.0",
86
87
  "memfs": "^3.2.2",
87
- "node-sass": "^6.0.0",
88
+ "node-sass": "^6.0.1",
88
89
  "node-sass-glob-importer": "^5.3.2",
89
90
  "npm-run-all": "^4.1.5",
90
- "prettier": "^2.3.0",
91
- "sass": "^1.32.12",
91
+ "prettier": "^2.3.2",
92
+ "sass": "^1.35.2",
92
93
  "semver": "^7.3.5",
93
- "standard-version": "^9.3.0",
94
- "style-loader": "^2.0.0",
95
- "webpack": "^5.36.2"
94
+ "standard-version": "^9.3.1",
95
+ "style-loader": "^3.2.1",
96
+ "webpack": "^5.45.1"
96
97
  },
97
98
  "keywords": [
98
99
  "sass",