sass-loader 14.2.1 → 15.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 +74 -51
- package/dist/index.js +1 -1
- package/dist/utils.js +7 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,25 +38,25 @@ or
|
|
|
38
38
|
pnpm add -D sass-loader sass webpack
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
> [!NOTE]
|
|
42
|
+
>
|
|
43
|
+
> 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`.
|
|
44
|
+
|
|
41
45
|
`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).
|
|
42
46
|
|
|
43
47
|
This allows you to control the versions of all your dependencies, and to choose which Sass implementation to use.
|
|
44
48
|
|
|
45
|
-
>
|
|
46
|
-
>
|
|
47
|
-
> We highly recommend using [Dart Sass](https://github.com/sass/dart-sass).
|
|
48
|
-
|
|
49
|
-
> **Warning**
|
|
49
|
+
> [!NOTE]
|
|
50
50
|
>
|
|
51
|
-
> [
|
|
51
|
+
> We highly recommend using [Sass Embedded](https://github.com/sass/embedded-host-node) or [Dart Sass](https://github.com/sass/dart-sass).
|
|
52
52
|
|
|
53
|
-
>
|
|
53
|
+
> [!WARNING]
|
|
54
54
|
>
|
|
55
|
-
> [Sass
|
|
55
|
+
> [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).
|
|
56
56
|
|
|
57
57
|
Chain the `sass-loader` with the [css-loader](https://github.com/webpack-contrib/css-loader) and the [style-loader](https://github.com/webpack-contrib/style-loader) to immediately apply all styles to the DOM or the [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) to extract it into a separate file.
|
|
58
58
|
|
|
59
|
-
Then add the loader to your
|
|
59
|
+
Then add the loader to your webpack configuration. For example:
|
|
60
60
|
|
|
61
61
|
**app.js**
|
|
62
62
|
|
|
@@ -106,14 +106,13 @@ For `production` mode, the `outputStyle` (old API) and `style` (new API) options
|
|
|
106
106
|
|
|
107
107
|
Webpack provides an [advanced mechanism to resolve files](https://webpack.js.org/concepts/module-resolution/).
|
|
108
108
|
|
|
109
|
-
The `sass-loader` uses Sass's custom importer feature to pass all queries to the
|
|
110
|
-
Thus you can import your Sass modules from `node_modules`.
|
|
109
|
+
The `sass-loader` uses Sass's custom importer feature to pass all queries to the webpack resolving engine enabling you to import your Sass modules from `node_modules`.
|
|
111
110
|
|
|
112
111
|
```scss
|
|
113
112
|
@import "bootstrap";
|
|
114
113
|
```
|
|
115
114
|
|
|
116
|
-
Using `~` is deprecated and
|
|
115
|
+
Using `~` is deprecated and should be removed from your code, but we still support it for historical reasons.
|
|
117
116
|
Why can you remove it? The loader will first try to resolve `@import` as a relative path. If it cannot be resolved, then the loader will try to resolve `@import` inside [`node_modules`](https://webpack.js.org/configuration/resolve/#resolvemodules).
|
|
118
117
|
|
|
119
118
|
Prepending module paths with a `~` tells webpack to search through [`node_modules`](https://webpack.js.org/configuration/resolve/#resolvemodules).
|
|
@@ -122,7 +121,7 @@ Prepending module paths with a `~` tells webpack to search through [`node_module
|
|
|
122
121
|
@import "~bootstrap";
|
|
123
122
|
```
|
|
124
123
|
|
|
125
|
-
It's important to prepend
|
|
124
|
+
It's important to prepend the path with only `~`, because `~/` resolves to the home directory.
|
|
126
125
|
Webpack needs to distinguish between `bootstrap` and `~bootstrap` because CSS and Sass files have no special syntax for importing relative files.
|
|
127
126
|
Writing `@import "style.scss"` is the same as `@import "./style.scss";`
|
|
128
127
|
|
|
@@ -133,9 +132,9 @@ Since Sass implementations don't provide [url rewriting](https://github.com/sass
|
|
|
133
132
|
- If you pass the generated CSS on to the `css-loader`, all urls must be relative to the entry-file (e.g. `main.scss`).
|
|
134
133
|
- If you're just generating CSS without passing it to the `css-loader`, it must be relative to your web root.
|
|
135
134
|
|
|
136
|
-
You
|
|
135
|
+
You might be surprised by this first issue, as it is natural to expect relative references to be resolved against the `.sass`/`.scss` file in which they are specified (like in regular `.css` files).
|
|
137
136
|
|
|
138
|
-
Thankfully there are
|
|
137
|
+
Thankfully there are two solutions to this problem:
|
|
139
138
|
|
|
140
139
|
- Add the missing url rewriting using the [resolve-url-loader](https://github.com/bholloway/resolve-url-loader). Place it before `sass-loader` in the loader chain.
|
|
141
140
|
- Library authors usually provide a variable to modify the asset path. [bootstrap-sass](https://github.com/twbs/bootstrap-sass) for example has an `$icon-font-path`.
|
|
@@ -161,8 +160,8 @@ Default: `sass`
|
|
|
161
160
|
|
|
162
161
|
The special `implementation` option determines which implementation of Sass to use.
|
|
163
162
|
|
|
164
|
-
By default the loader
|
|
165
|
-
Just add
|
|
163
|
+
By default, the loader resolves the implementation based on your dependencies.
|
|
164
|
+
Just add the desired implementation to your `package.json` (`sass`, `sass-embedded`, or `node-sass` package) and install dependencies.
|
|
166
165
|
|
|
167
166
|
Example where the `sass-loader` loader uses the `sass` (`dart-sass`) implementation:
|
|
168
167
|
|
|
@@ -190,14 +189,38 @@ Example where the `sass-loader` loader uses the `node-sass` implementation:
|
|
|
190
189
|
}
|
|
191
190
|
```
|
|
192
191
|
|
|
193
|
-
|
|
194
|
-
In order to avoid this situation you can use the `implementation` option.
|
|
192
|
+
Example where the `sass-loader` loader uses the `sass-embedded` implementation:
|
|
195
193
|
|
|
196
|
-
|
|
194
|
+
**package.json**
|
|
195
|
+
|
|
196
|
+
```json
|
|
197
|
+
{
|
|
198
|
+
"devDependencies": {
|
|
199
|
+
"sass-loader": "^7.2.0",
|
|
200
|
+
"sass": "^1.22.10"
|
|
201
|
+
},
|
|
202
|
+
"optionalDependencies": {
|
|
203
|
+
"sass-embedded": "^1.70.0"
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
> [!NOTE]
|
|
209
|
+
>
|
|
210
|
+
> Using `optionalDependencies` means that `sass-loader` can fallback to `sass`
|
|
211
|
+
> when running on an operating system not supported by `sass-embedded`
|
|
212
|
+
|
|
213
|
+
Be aware of the order that `sass-loader` will resolve the implementation:
|
|
214
|
+
|
|
215
|
+
1. `sass-embedded`
|
|
216
|
+
2. `sass`
|
|
217
|
+
3. `node-sass`
|
|
218
|
+
|
|
219
|
+
You can specify a specific implementation by using the `implementation` option, which accepts one of the above values.
|
|
197
220
|
|
|
198
221
|
#### `object`
|
|
199
222
|
|
|
200
|
-
For example, to use Dart Sass, you'd pass:
|
|
223
|
+
For example, to always use Dart Sass, you'd pass:
|
|
201
224
|
|
|
202
225
|
```js
|
|
203
226
|
module.exports = {
|
|
@@ -211,7 +234,7 @@ module.exports = {
|
|
|
211
234
|
{
|
|
212
235
|
loader: "sass-loader",
|
|
213
236
|
options: {
|
|
214
|
-
// Prefer `dart-sass`
|
|
237
|
+
// Prefer `dart-sass`, even if `sass-embedded` is available
|
|
215
238
|
implementation: require("sass"),
|
|
216
239
|
},
|
|
217
240
|
},
|
|
@@ -238,7 +261,7 @@ module.exports = {
|
|
|
238
261
|
{
|
|
239
262
|
loader: "sass-loader",
|
|
240
263
|
options: {
|
|
241
|
-
// Prefer `dart-sass`
|
|
264
|
+
// Prefer `dart-sass`, even if `sass-embedded` is available
|
|
242
265
|
implementation: require.resolve("sass"),
|
|
243
266
|
},
|
|
244
267
|
},
|
|
@@ -267,27 +290,27 @@ Default: defaults values for Sass implementation
|
|
|
267
290
|
|
|
268
291
|
Options for [Dart Sass](http://sass-lang.com/dart-sass) or [Node Sass](https://github.com/sass/node-sass) implementation.
|
|
269
292
|
|
|
270
|
-
>
|
|
293
|
+
> [!NOTE]
|
|
271
294
|
>
|
|
272
|
-
> The `charset` option
|
|
295
|
+
> The `charset` option is `true` by default for `dart-sass`, we strongly discourage setting this to `false`, because webpack doesn't support files other than `utf-8`.
|
|
273
296
|
|
|
274
|
-
>
|
|
297
|
+
> [!NOTE]
|
|
275
298
|
>
|
|
276
|
-
> The `indentedSyntax` option
|
|
299
|
+
> The `indentedSyntax` option is `true` for the `sass` extension.
|
|
277
300
|
|
|
278
|
-
>
|
|
301
|
+
> [!NOTE]
|
|
279
302
|
>
|
|
280
303
|
> Options such as `data` and `file` are unavailable and will be ignored.
|
|
281
304
|
|
|
282
|
-
> ℹ We strongly discourage
|
|
305
|
+
> ℹ We strongly discourage changing the `outFile`, `sourceMapContents`, `sourceMapEmbed`, and `sourceMapRoot` options because `sass-loader` sets these automatically when the `sourceMap` option is `true`.
|
|
283
306
|
|
|
284
|
-
>
|
|
307
|
+
> [!NOTE]
|
|
285
308
|
>
|
|
286
309
|
> 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
310
|
|
|
288
|
-
There is a slight difference between the `sass` (`dart-sass`) and `node-sass
|
|
311
|
+
There is a slight difference between the options for `sass` (`dart-sass`) and `node-sass`.
|
|
289
312
|
|
|
290
|
-
Please consult documentation before using them:
|
|
313
|
+
Please consult their respective documentation before using them:
|
|
291
314
|
|
|
292
315
|
- [Dart Sass documentation](https://sass-lang.com/documentation/js-api/interfaces/Options) for all available `sass` options.
|
|
293
316
|
- [Node Sass documentation](https://github.com/sass/node-sass/#options) for all available `node-sass` options.
|
|
@@ -325,7 +348,7 @@ module.exports = {
|
|
|
325
348
|
|
|
326
349
|
#### `function`
|
|
327
350
|
|
|
328
|
-
Allows
|
|
351
|
+
Allows configuring the Sass implementation with different options based on the loader context.
|
|
329
352
|
|
|
330
353
|
```js
|
|
331
354
|
module.exports = {
|
|
@@ -376,9 +399,9 @@ Default: depends on the `compiler.devtool` value
|
|
|
376
399
|
Enables/Disables generation of source maps.
|
|
377
400
|
|
|
378
401
|
By default generation of source maps depends on the [`devtool`](https://webpack.js.org/configuration/devtool/) option.
|
|
379
|
-
All values enable source map generation except `eval` and `false
|
|
402
|
+
All values enable source map generation except `eval` and `false`.
|
|
380
403
|
|
|
381
|
-
> ℹ If
|
|
404
|
+
> ℹ If `true`, the `sourceMap`, `sourceMapRoot`, `sourceMapEmbed`, `sourceMapContents` and `omitSourceMapUrl` options from `sassOptions` will be ignored.
|
|
382
405
|
|
|
383
406
|
**webpack.config.js**
|
|
384
407
|
|
|
@@ -410,8 +433,8 @@ module.exports = {
|
|
|
410
433
|
```
|
|
411
434
|
|
|
412
435
|
> ℹ In some rare cases `node-sass` can output invalid source maps (it is a `node-sass` bug).
|
|
413
|
-
|
|
414
|
-
>
|
|
436
|
+
>
|
|
437
|
+
> In order to avoid this, you can try to update `node-sass` to latest version, or you can try to set within `sassOptions` the `outputStyle` option to `compressed`.
|
|
415
438
|
|
|
416
439
|
**webpack.config.js**
|
|
417
440
|
|
|
@@ -561,10 +584,10 @@ type webpackImporter = boolean;
|
|
|
561
584
|
|
|
562
585
|
Default: `true`
|
|
563
586
|
|
|
564
|
-
Enables/Disables the default
|
|
587
|
+
Enables/Disables the default webpack importer.
|
|
565
588
|
|
|
566
|
-
This can improve performance in some cases
|
|
567
|
-
You can pass own `importer` to solve this (see [`importer docs`](https://github.com/sass/node-sass#importer--v200---experimental)).
|
|
589
|
+
This can improve performance in some cases, though use it with caution because aliases and `@import` at-rules starting with `~` will not work.
|
|
590
|
+
You can pass your own `importer` to solve this (see [`importer docs`](https://github.com/sass/node-sass#importer--v200---experimental)).
|
|
568
591
|
|
|
569
592
|
**webpack.config.js**
|
|
570
593
|
|
|
@@ -624,7 +647,7 @@ $known-prefixes: webkit, moz, ms, o;
|
|
|
624
647
|
}
|
|
625
648
|
```
|
|
626
649
|
|
|
627
|
-
The presented code will throw webpack warning instead logging.
|
|
650
|
+
The presented code will throw a webpack warning instead logging.
|
|
628
651
|
|
|
629
652
|
To ignore unnecessary warnings you can use the [ignoreWarnings](https://webpack.js.org/configuration/other-options/#ignorewarnings) option.
|
|
630
653
|
|
|
@@ -662,15 +685,15 @@ type api = "legacy" | "modern" | "modern-compiler";
|
|
|
662
685
|
|
|
663
686
|
Default: `"legacy"`
|
|
664
687
|
|
|
665
|
-
Allows you to switch between `legacy` and `modern`
|
|
688
|
+
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).
|
|
666
689
|
|
|
667
|
-
>
|
|
690
|
+
> [!NOTE]
|
|
668
691
|
>
|
|
669
692
|
> Using `modern-compiler` and `sass-embedded` together significantly improve performance and decrease built time. We strongly recommend their use. We will enable them by default in a future major release.
|
|
670
693
|
|
|
671
|
-
>
|
|
694
|
+
> [!WARNING]
|
|
672
695
|
>
|
|
673
|
-
> The sass options are different for `
|
|
696
|
+
> The sass options are different for the `legacy` and `modern` APIs. Please look at [docs](https://sass-lang.com/documentation/js-api) how to migrate to the modern options.
|
|
674
697
|
|
|
675
698
|
**webpack.config.js**
|
|
676
699
|
|
|
@@ -701,8 +724,8 @@ module.exports = {
|
|
|
701
724
|
|
|
702
725
|
## How to enable `@debug` output
|
|
703
726
|
|
|
704
|
-
|
|
705
|
-
|
|
727
|
+
By default, the output of `@debug` messages are disabled.
|
|
728
|
+
Add the following to **webpack.config.js** to enable them:
|
|
706
729
|
|
|
707
730
|
```js
|
|
708
731
|
module.exports = {
|
|
@@ -717,9 +740,9 @@ module.exports = {
|
|
|
717
740
|
|
|
718
741
|
### Extracts CSS into separate files
|
|
719
742
|
|
|
720
|
-
For production builds it's recommended to extract the CSS from your bundle
|
|
743
|
+
For production builds it's recommended to extract the CSS from your bundle to be able to use parallel loading of CSS/JS resources later on.
|
|
721
744
|
|
|
722
|
-
There are four
|
|
745
|
+
There are four recommended ways to extract a stylesheet from a bundle:
|
|
723
746
|
|
|
724
747
|
#### 1. [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin)
|
|
725
748
|
|
|
@@ -785,7 +808,7 @@ module.exports = {
|
|
|
785
808
|
|
|
786
809
|
#### 3. [extract-loader](https://github.com/peerigon/extract-loader) (simpler, but specialized on the css-loader's output)
|
|
787
810
|
|
|
788
|
-
#### 4. [file-loader](https://github.com/webpack-contrib/file-loader) (deprecated--should only be used in
|
|
811
|
+
#### 4. [file-loader](https://github.com/webpack-contrib/file-loader) (deprecated--should only be used in webpack v4)
|
|
789
812
|
|
|
790
813
|
**webpack.config.js**
|
|
791
814
|
|
|
@@ -821,7 +844,7 @@ module.exports = {
|
|
|
821
844
|
|
|
822
845
|
Enables/Disables generation of source maps.
|
|
823
846
|
|
|
824
|
-
To enable CSS source maps, you'll need to pass the `sourceMap` option to the `sass-loader` _and_ the css-loader
|
|
847
|
+
To enable CSS source maps, you'll need to pass the `sourceMap` option to the `sass-loader` _and_ the `css-loader`.
|
|
825
848
|
|
|
826
849
|
**webpack.config.js**
|
|
827
850
|
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ var _url = _interopRequireDefault(require("url"));
|
|
|
8
8
|
var _path = _interopRequireDefault(require("path"));
|
|
9
9
|
var _options = _interopRequireDefault(require("./options.json"));
|
|
10
10
|
var _utils = require("./utils");
|
|
11
|
-
function _interopRequireDefault(
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
12
|
/**
|
|
13
13
|
* The sass-loader makes node-sass and dart-sass available to webpack modules.
|
|
14
14
|
*
|
package/dist/utils.js
CHANGED
|
@@ -13,19 +13,19 @@ exports.getWebpackResolver = getWebpackResolver;
|
|
|
13
13
|
exports.normalizeSourceMap = normalizeSourceMap;
|
|
14
14
|
var _url = _interopRequireDefault(require("url"));
|
|
15
15
|
var _path = _interopRequireDefault(require("path"));
|
|
16
|
-
function _interopRequireDefault(
|
|
16
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
17
|
function getDefaultSassImplementation() {
|
|
18
18
|
let sassImplPkg = "sass";
|
|
19
19
|
try {
|
|
20
|
-
require.resolve("sass");
|
|
20
|
+
require.resolve("sass-embedded");
|
|
21
|
+
sassImplPkg = "sass-embedded";
|
|
21
22
|
} catch (ignoreError) {
|
|
22
23
|
try {
|
|
23
|
-
require.resolve("
|
|
24
|
-
sassImplPkg = "node-sass";
|
|
24
|
+
require.resolve("sass");
|
|
25
25
|
} catch (_ignoreError) {
|
|
26
26
|
try {
|
|
27
|
-
require.resolve("sass
|
|
28
|
-
sassImplPkg = "sass
|
|
27
|
+
require.resolve("node-sass");
|
|
28
|
+
sassImplPkg = "node-sass";
|
|
29
29
|
} catch (__ignoreError) {
|
|
30
30
|
sassImplPkg = "sass";
|
|
31
31
|
}
|
|
@@ -503,6 +503,7 @@ function getModernWebpackImporter(loaderContext, implementation, loadPaths) {
|
|
|
503
503
|
syntax = "scss";
|
|
504
504
|
}
|
|
505
505
|
try {
|
|
506
|
+
// eslint-disable-next-line no-shadow
|
|
506
507
|
const contents = await new Promise((resolve, reject) => {
|
|
507
508
|
// Old version of `enhanced-resolve` supports only path as a string
|
|
508
509
|
// TODO simplify in the next major release and pass URL
|