sass-loader 16.0.7 → 17.0.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
@@ -43,7 +43,7 @@ pnpm add -D sass-loader sass webpack
43
43
  >
44
44
  > To enable CSS processing in your project, you need to install [style-loader](https://webpack.js.org/loaders/style-loader/) and [css-loader](https://webpack.js.org/loaders/css-loader/) via `npm i style-loader css-loader`.
45
45
 
46
- `sass-loader` requires you to install either [Dart Sass](https://github.com/sass/dart-sass), [Node Sass](https://github.com/sass/node-sass) on your own (more documentation can be found below) or [Sass Embedded](https://github.com/sass/embedded-host-node).
46
+ `sass-loader` requires you to install either [Dart Sass](https://github.com/sass/dart-sass) or [Sass Embedded](https://github.com/sass/embedded-host-node) on your own (more documentation can be found below).
47
47
 
48
48
  This allows you to control the versions of all your dependencies and to choose which Sass implementation to use.
49
49
 
@@ -51,10 +51,6 @@ This allows you to control the versions of all your dependencies and to choose w
51
51
  >
52
52
  > We highly recommend using [Sass Embedded](https://github.com/sass/embedded-host-node) or [Dart Sass](https://github.com/sass/dart-sass).
53
53
 
54
- > [!WARNING]
55
- >
56
- > [Node Sass](https://github.com/sass/node-sass) does not work with [Yarn PnP](https://classic.yarnpkg.com/en/docs/pnp/) and doesn't support [@use rule](https://sass-lang.com/documentation/at-rules/use).
57
-
58
54
  Chain the `sass-loader` with the [css-loader](https://github.com/webpack/css-loader) and the [style-loader](https://github.com/webpack/style-loader) to immediately apply all styles to the DOM, or with the [mini-css-extract-plugin](https://github.com/webpack/mini-css-extract-plugin) to extract it into a separate file.
59
55
 
60
56
  Then add the loader to your webpack configuration. For example:
@@ -99,9 +95,9 @@ module.exports = {
99
95
 
100
96
  Finally run `webpack` via your preferred method (e.g., via CLI or an npm script).
101
97
 
102
- ### The `style` (new API, by default since 16 version) and `outputStyle` (old API) options in `production` mode
98
+ ### The `style` option in `production` mode
103
99
 
104
- For `production` mode, the `style` (new API, by default since 16 version) and `outputStyle` (old API) options default to `compressed` unless otherwise specified in `sassOptions`.
100
+ For `production` mode, the `style` option defaults to `compressed` unless otherwise specified in `sassOptions`.
105
101
 
106
102
  ### Resolving `import` and `use` at-rules
107
103
 
@@ -167,7 +163,7 @@ Default: `sass`
167
163
  The special `implementation` option determines which implementation of Sass to use.
168
164
 
169
165
  By default, the loader resolves the implementation based on your dependencies.
170
- Just add the desired implementation to your `package.json` (`sass`, `sass-embedded`, or `node-sass` package) and install dependencies.
166
+ Just add the desired implementation to your `package.json` (`sass` or `sass-embedded` package) and install dependencies.
171
167
 
172
168
  Example where the `sass-loader` uses the `sass` (`dart-sass`) implementation:
173
169
 
@@ -182,19 +178,6 @@ Example where the `sass-loader` uses the `sass` (`dart-sass`) implementation:
182
178
  }
183
179
  ```
184
180
 
185
- Example where the `sass-loader` uses the `node-sass` implementation:
186
-
187
- **package.json**
188
-
189
- ```json
190
- {
191
- "devDependencies": {
192
- "sass-loader": "^7.2.0",
193
- "node-sass": "^5.0.0"
194
- }
195
- }
196
- ```
197
-
198
181
  Example where the `sass-loader` uses the `sass-embedded` implementation:
199
182
 
200
183
  **package.json**
@@ -219,7 +202,6 @@ Be aware of the order that `sass-loader` will resolve the implementation:
219
202
 
220
203
  1. `sass-embedded`
221
204
  2. `sass`
222
- 3. `node-sass`
223
205
 
224
206
  You can specify a specific implementation by using the `implementation` option, which accepts one of the above values.
225
207
 
@@ -283,17 +265,17 @@ Type:
283
265
 
284
266
  ```ts
285
267
  type sassOptions =
286
- | import("sass").LegacyOptions<"async">
268
+ | import("sass").StringOptionsWithImporter<"async">
287
269
  | ((
288
270
  content: string | Buffer,
289
271
  loaderContext: LoaderContext,
290
272
  meta: any,
291
- ) => import("sass").LegacyOptions<"async">);
273
+ ) => import("sass").StringOptionsWithImporter<"async">);
292
274
  ```
293
275
 
294
276
  Default: defaults values for Sass implementation
295
277
 
296
- Options for [Dart Sass](http://sass-lang.com/dart-sass) or [Node Sass](https://github.com/sass/node-sass) implementation.
278
+ Options for [Dart Sass](http://sass-lang.com/dart-sass) or [Sass Embedded](https://github.com/sass/embedded-host-node) implementation.
297
279
 
298
280
  > [!NOTE]
299
281
  >
@@ -301,25 +283,18 @@ Options for [Dart Sass](http://sass-lang.com/dart-sass) or [Node Sass](https://g
301
283
 
302
284
  > [!NOTE]
303
285
  >
304
- > The `syntax` (new API, by default since 16 version) and `indentedSyntax` (old API) option is `scss` for the `scss` extension, `indented` for the `sass` extension, and `css` for the `css` extension.
305
-
306
- > [!NOTE]
307
- >
308
- > Options such as `data` and `file` are unavailable and will be ignored.
309
-
310
- > ℹ We strongly discourage changing the `sourceMap` (new API, by default since 16 version), `outFile` (old API), `sourceMapContents` (old API), `sourceMapEmbed` (old API), and `sourceMapRoot` (old API) options because `sass-loader` sets these automatically when the `sourceMap` option is `true`.
286
+ > The `syntax` option is `scss` for the `scss` extension, `indented` for the `sass` extension, and `css` for the `css` extension.
311
287
 
312
288
  > [!NOTE]
313
289
  >
314
- > 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.
290
+ > Options such as `data` and `url` are unavailable and will be ignored.
315
291
 
316
- There is a slight difference between the options for `sass` (`dart-sass`) and `node-sass`.
292
+ > We strongly discourage changing the `sourceMap` option because `sass-loader` sets it automatically when the `sourceMap` option is `true`.
317
293
 
318
294
  Please consult their respective documentation before using them:
319
295
 
320
296
  - [Dart Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options) for all available `sass` options.
321
- - [Sass Embedded documentation](https://github.com/sass/embedded-host-node) for all available `sass` options.
322
- - [Node Sass documentation](https://github.com/sass/node-sass/#options) for all available `node-sass` options.
297
+ - [Sass Embedded documentation](https://github.com/sass/embedded-host-node) for all available `sass-embedded` options.
323
298
 
324
299
  #### `object`
325
300
 
@@ -407,7 +382,7 @@ Enables/disables generation of source maps.
407
382
  By default generation of source maps depends on the [`devtool`](https://webpack.js.org/configuration/devtool/) option.
408
383
  All values enable source map generation except `eval` and `false`.
409
384
 
410
- > ℹ If `true`, the `sourceMap` (new API, by default since 16 version), `outFile` (old API), `sourceMapContents` (old API), `sourceMapEmbed` (old API), and `sourceMapRoot` (old API) from `sassOptions` will be ignored.
385
+ > ℹ If `true`, the `sourceMap` option from `sassOptions` will be ignored.
411
386
 
412
387
  **webpack.config.js**
413
388
 
@@ -438,10 +413,6 @@ module.exports = {
438
413
  };
439
414
  ```
440
415
 
441
- > ℹ In some rare cases `node-sass` can output invalid source maps (this is a `node-sass` bug).
442
- >
443
- > In order to avoid this, you can try to update `node-sass` to the latest version, or you can try to set within `sassOptions` the `outputStyle` option to `compressed`.
444
-
445
416
  **webpack.config.js**
446
417
 
447
418
  ```js
@@ -458,7 +429,7 @@ module.exports = {
458
429
  options: {
459
430
  sourceMap: true,
460
431
  sassOptions: {
461
- outputStyle: "compressed",
432
+ style: "compressed",
462
433
  },
463
434
  },
464
435
  },
@@ -593,7 +564,7 @@ Default: `true`
593
564
  Enables/disables the default webpack importer.
594
565
 
595
566
  This can improve performance in some cases, though use it with caution because aliases and `@import` at-rules starting with `~` will not work.
596
- You can pass your own `importer` to solve this (see [`importer` docs](https://github.com/sass/node-sass#importer--v200---experimental)).
567
+ You can pass your own `importer` to solve this (see [Sass importer documentation](https://sass-lang.com/documentation/js-api/interfaces/LegacyImporter)).
597
568
 
598
569
  **webpack.config.js**
599
570
 
@@ -686,20 +657,22 @@ module.exports = {
686
657
  Type:
687
658
 
688
659
  ```ts
689
- type api = "legacy" | "modern" | "modern-compiler";
660
+ type api = "auto" | "modern" | "modern-compiler";
690
661
  ```
691
662
 
692
- Default: `"modern"` for `sass` (`dart-sass`) and `sass-embedded`, or `"legacy"` for `node-sass`
663
+ Default: `"auto"` for `sass` (`dart-sass`) and `sass-embedded`
693
664
 
694
- Allows you to switch between the `legacy` and `modern` APIs. You can find more information [here](https://sass-lang.com/documentation/js-api). The `modern-compiler` option enables the modern API with support for [Shared Resources](https://github.com/sass/sass/blob/main/accepted/shared-resources.d.ts.md).
665
+ Allows you to switch between the `modern` and `modern-compiler` APIs. You can find more information [here](https://sass-lang.com/documentation/js-api). The `modern-compiler` option enables the modern API with support for [Shared Resources](https://github.com/sass/sass/blob/main/accepted/shared-resources.d.ts.md).
666
+
667
+ When `"auto"` is used, the loader picks `"modern-compiler"` whenever the implementation exposes `initAsyncCompiler` (i.e. recent versions of `sass` and `sass-embedded`) and falls back to `"modern"` otherwise. Combined with `sass-embedded`, this yields the best build performance out of the box.
695
668
 
696
669
  > [!NOTE]
697
670
  >
698
- > Using `modern-compiler` and `sass-embedded` together significantly improves performance and decreases build time. We strongly recommend their use. We will enable them by default in a future major release.
671
+ > Using `modern-compiler` and `sass-embedded` together significantly improves performance and decreases build time. They are now selected automatically by the default `"auto"` API.
699
672
 
700
- > [!WARNING]
673
+ > [!NOTE]
701
674
  >
702
- > The Sass options are different for the `legacy` and `modern` APIs. Please look at [docs](https://sass-lang.com/documentation/js-api) to learn how to migrate to the modern options.
675
+ > The legacy Sass JS API is no longer supported. If you were using `api: "legacy"`, please migrate to the modern API. See the [Sass JS API docs](https://sass-lang.com/documentation/js-api) to learn how to migrate.
703
676
 
704
677
  **webpack.config.js**
705
678
 
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _nodePath = _interopRequireDefault(require("node:path"));
8
+ var _nodeUrl = _interopRequireDefault(require("node:url"));
9
+ var _options = _interopRequireDefault(require("./options.json"));
10
+ var _utils = require("./utils.js");
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ /** @typedef {import("webpack").LoaderContext<LoaderOptions>} LoaderContext */
13
+ /** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
14
+ /** @typedef {import("./utils.js").LoaderOptions} LoaderOptions */
15
+ /** @typedef {import("./utils.js").SassError} SassError */
16
+
17
+ /**
18
+ * The sass-loader makes dart-sass and sass-embedded available to webpack modules.
19
+ * @this {LoaderContext}
20
+ * @param {string} content content
21
+ * @returns {Promise<void>} loader result
22
+ */
23
+ async function loader(content) {
24
+ const options = this.getOptions(/** @type {Schema} */_options.default);
25
+ const callback = this.async();
26
+ let implementation;
27
+ try {
28
+ implementation = await (0, _utils.getSassImplementation)(options.implementation);
29
+ } catch (error) {
30
+ callback(/** @type {Error} */error);
31
+ return;
32
+ }
33
+ const useSourceMap = typeof options.sourceMap === "boolean" ? options.sourceMap : this.sourceMap === true;
34
+ const sassOptions = await (0, _utils.getSassOptions)(this, options, content, useSourceMap);
35
+ const shouldUseWebpackImporter = typeof options.webpackImporter === "boolean" ? options.webpackImporter : true;
36
+ if (shouldUseWebpackImporter) {
37
+ sassOptions.importers.push((0, _utils.getModernWebpackImporter)(this));
38
+ }
39
+ let compile;
40
+ try {
41
+ compile = (0, _utils.getCompileFn)(this, implementation, options.api);
42
+ } catch (error) {
43
+ callback(/** @type {Error} */error);
44
+ return;
45
+ }
46
+ let result;
47
+ try {
48
+ result = await compile(sassOptions);
49
+ } catch (error) {
50
+ const sassError = /** @type {SassError} */error;
51
+
52
+ // There are situations when the `span.url` property does not exist
53
+ if (sassError.span && typeof sassError.span.url !== "undefined") {
54
+ this.addDependency(_nodeUrl.default.fileURLToPath(sassError.span.url));
55
+ }
56
+ callback((0, _utils.errorFactory)(sassError));
57
+ return;
58
+ }
59
+ let map = result.sourceMap || undefined;
60
+
61
+ // Modify source paths only for webpack, otherwise we do nothing
62
+ if (map && useSourceMap) {
63
+ map = (0, _utils.normalizeSourceMap)(map, this.rootContext);
64
+ }
65
+ if (typeof result.loadedUrls !== "undefined") {
66
+ for (const includedFile of result.loadedUrls.filter(loadedUrl => loadedUrl.protocol === "file:")) {
67
+ const normalizedIncludedFile = _nodeUrl.default.fileURLToPath(includedFile);
68
+
69
+ // Custom `importer` can return only `contents` so includedFile will be relative
70
+ if (_nodePath.default.isAbsolute(normalizedIncludedFile)) {
71
+ this.addDependency(normalizedIncludedFile);
72
+ }
73
+ }
74
+ }
75
+ callback(null, result.css.toString(), map || undefined);
76
+ }
77
+ var _default = exports.default = loader;module.exports = exports.default;
78
+ module.exports.default = exports.default;
@@ -15,12 +15,12 @@
15
15
  ]
16
16
  },
17
17
  "api": {
18
- "description": "Switch between old and modern API for `sass` (`Dart Sass`) and `Sass Embedded` implementations.",
18
+ "description": "Switch between `auto`, `modern` and `modern-compiler` API for `sass` (`Dart Sass`) and `Sass Embedded` implementations.",
19
19
  "link": "https://github.com/webpack/sass-loader#sassoptions",
20
- "enum": ["legacy", "modern", "modern-compiler"]
20
+ "enum": ["auto", "modern", "modern-compiler"]
21
21
  },
22
22
  "sassOptions": {
23
- "description": "Options for `node-sass` or `sass` (`Dart Sass`) implementation.",
23
+ "description": "Options for `sass` (`Dart Sass`) or `sass-embedded` implementation.",
24
24
  "link": "https://github.com/webpack/sass-loader#sassoptions",
25
25
  "anyOf": [
26
26
  {
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}