sass-loader 10.0.5 → 10.2.1
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 +98 -60
- package/dist/SassError.js +2 -2
- package/dist/cjs.js +1 -1
- package/dist/index.js +20 -9
- package/dist/utils.js +78 -63
- package/package.json +16 -16
- package/CHANGELOG.md +0 -528
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ Then add the loader to your Webpack configuration. For example:
|
|
|
42
42
|
**app.js**
|
|
43
43
|
|
|
44
44
|
```js
|
|
45
|
-
import
|
|
45
|
+
import "./style.scss";
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
**style.scss**
|
|
@@ -65,11 +65,11 @@ module.exports = {
|
|
|
65
65
|
test: /\.s[ac]ss$/i,
|
|
66
66
|
use: [
|
|
67
67
|
// Creates `style` nodes from JS strings
|
|
68
|
-
|
|
68
|
+
"style-loader",
|
|
69
69
|
// Translates CSS into CommonJS
|
|
70
|
-
|
|
70
|
+
"css-loader",
|
|
71
71
|
// Compiles Sass to CSS
|
|
72
|
-
|
|
72
|
+
"sass-loader",
|
|
73
73
|
],
|
|
74
74
|
},
|
|
75
75
|
],
|
|
@@ -86,7 +86,7 @@ Webpack provides an [advanced mechanism to resolve files](https://webpack.js.org
|
|
|
86
86
|
The `sass-loader` uses Sass's custom importer feature to pass all queries to the Webpack resolving engine. Thus you can import your Sass modules from `node_modules`. Just prepend them with a `~` to tell Webpack that this is not a relative import:
|
|
87
87
|
|
|
88
88
|
```scss
|
|
89
|
-
@import
|
|
89
|
+
@import "~bootstrap";
|
|
90
90
|
```
|
|
91
91
|
|
|
92
92
|
It's important to only prepend it with `~`, because `~/` resolves to the home directory.
|
|
@@ -167,13 +167,13 @@ module.exports = {
|
|
|
167
167
|
{
|
|
168
168
|
test: /\.s[ac]ss$/i,
|
|
169
169
|
use: [
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
"style-loader",
|
|
171
|
+
"css-loader",
|
|
172
172
|
{
|
|
173
|
-
loader:
|
|
173
|
+
loader: "sass-loader",
|
|
174
174
|
options: {
|
|
175
175
|
// Prefer `dart-sass`
|
|
176
|
-
implementation: require(
|
|
176
|
+
implementation: require("sass"),
|
|
177
177
|
},
|
|
178
178
|
},
|
|
179
179
|
],
|
|
@@ -186,7 +186,9 @@ module.exports = {
|
|
|
186
186
|
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.
|
|
187
187
|
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.
|
|
188
188
|
|
|
189
|
-
We automatically inject the [`fibers`](https://github.com/laverdet/node-fibers) package (setup `sassOptions.fiber`) if is possible (i.e. you need install the [`fibers`](https://github.com/laverdet/node-fibers) package).
|
|
189
|
+
We automatically inject the [`fibers`](https://github.com/laverdet/node-fibers) package (setup `sassOptions.fiber`) for `Node.js` less v16.0.0 if is possible (i.e. you need install the [`fibers`](https://github.com/laverdet/node-fibers) package).
|
|
190
|
+
|
|
191
|
+
> Fibers is not compatible with `Node.js` v16.0.0 or later ([see introduction to readme](https://github.com/laverdet/node-fibers)).
|
|
190
192
|
|
|
191
193
|
**package.json**
|
|
192
194
|
|
|
@@ -211,12 +213,12 @@ module.exports = {
|
|
|
211
213
|
{
|
|
212
214
|
test: /\.s[ac]ss$/i,
|
|
213
215
|
use: [
|
|
214
|
-
|
|
215
|
-
|
|
216
|
+
"style-loader",
|
|
217
|
+
"css-loader",
|
|
216
218
|
{
|
|
217
|
-
loader:
|
|
219
|
+
loader: "sass-loader",
|
|
218
220
|
options: {
|
|
219
|
-
implementation: require(
|
|
221
|
+
implementation: require("sass"),
|
|
220
222
|
sassOptions: {
|
|
221
223
|
fiber: false,
|
|
222
224
|
},
|
|
@@ -240,14 +242,14 @@ module.exports = {
|
|
|
240
242
|
{
|
|
241
243
|
test: /\.s[ac]ss$/i,
|
|
242
244
|
use: [
|
|
243
|
-
|
|
244
|
-
|
|
245
|
+
"style-loader",
|
|
246
|
+
"css-loader",
|
|
245
247
|
{
|
|
246
|
-
loader:
|
|
248
|
+
loader: "sass-loader",
|
|
247
249
|
options: {
|
|
248
|
-
implementation: require(
|
|
250
|
+
implementation: require("sass"),
|
|
249
251
|
sassOptions: {
|
|
250
|
-
fiber: require(
|
|
252
|
+
fiber: require("fibers"),
|
|
251
253
|
},
|
|
252
254
|
},
|
|
253
255
|
},
|
|
@@ -293,14 +295,14 @@ module.exports = {
|
|
|
293
295
|
{
|
|
294
296
|
test: /\.s[ac]ss$/i,
|
|
295
297
|
use: [
|
|
296
|
-
|
|
297
|
-
|
|
298
|
+
"style-loader",
|
|
299
|
+
"css-loader",
|
|
298
300
|
{
|
|
299
|
-
loader:
|
|
301
|
+
loader: "sass-loader",
|
|
300
302
|
options: {
|
|
301
303
|
sassOptions: {
|
|
302
304
|
indentWidth: 4,
|
|
303
|
-
includePaths: [
|
|
305
|
+
includePaths: ["absolute/path/a", "absolute/path/b"],
|
|
304
306
|
},
|
|
305
307
|
},
|
|
306
308
|
},
|
|
@@ -322,24 +324,24 @@ module.exports = {
|
|
|
322
324
|
{
|
|
323
325
|
test: /\.s[ac]ss$/i,
|
|
324
326
|
use: [
|
|
325
|
-
|
|
326
|
-
|
|
327
|
+
"style-loader",
|
|
328
|
+
"css-loader",
|
|
327
329
|
{
|
|
328
|
-
loader:
|
|
330
|
+
loader: "sass-loader",
|
|
329
331
|
options: {
|
|
330
332
|
sassOptions: (loaderContext) => {
|
|
331
333
|
// More information about available properties https://webpack.js.org/api/loaders/
|
|
332
334
|
const { resourcePath, rootContext } = loaderContext;
|
|
333
335
|
const relativePath = path.relative(rootContext, resourcePath);
|
|
334
336
|
|
|
335
|
-
if (relativePath ===
|
|
337
|
+
if (relativePath === "styles/foo.scss") {
|
|
336
338
|
return {
|
|
337
|
-
includePaths: [
|
|
339
|
+
includePaths: ["absolute/path/c", "absolute/path/d"],
|
|
338
340
|
};
|
|
339
341
|
}
|
|
340
342
|
|
|
341
343
|
return {
|
|
342
|
-
includePaths: [
|
|
344
|
+
includePaths: ["absolute/path/a", "absolute/path/b"],
|
|
343
345
|
};
|
|
344
346
|
},
|
|
345
347
|
},
|
|
@@ -372,15 +374,15 @@ module.exports = {
|
|
|
372
374
|
{
|
|
373
375
|
test: /\.s[ac]ss$/i,
|
|
374
376
|
use: [
|
|
375
|
-
|
|
377
|
+
"style-loader",
|
|
376
378
|
{
|
|
377
|
-
loader:
|
|
379
|
+
loader: "css-loader",
|
|
378
380
|
options: {
|
|
379
381
|
sourceMap: true,
|
|
380
382
|
},
|
|
381
383
|
},
|
|
382
384
|
{
|
|
383
|
-
loader:
|
|
385
|
+
loader: "sass-loader",
|
|
384
386
|
options: {
|
|
385
387
|
sourceMap: true,
|
|
386
388
|
},
|
|
@@ -405,14 +407,14 @@ module.exports = {
|
|
|
405
407
|
{
|
|
406
408
|
test: /\.s[ac]ss$/i,
|
|
407
409
|
use: [
|
|
408
|
-
|
|
409
|
-
|
|
410
|
+
"style-loader",
|
|
411
|
+
"css-loader",
|
|
410
412
|
{
|
|
411
|
-
loader:
|
|
413
|
+
loader: "sass-loader",
|
|
412
414
|
options: {
|
|
413
415
|
sourceMap: true,
|
|
414
416
|
sassOptions: {
|
|
415
|
-
outputStyle:
|
|
417
|
+
outputStyle: "compressed",
|
|
416
418
|
},
|
|
417
419
|
},
|
|
418
420
|
},
|
|
@@ -442,12 +444,12 @@ module.exports = {
|
|
|
442
444
|
{
|
|
443
445
|
test: /\.s[ac]ss$/i,
|
|
444
446
|
use: [
|
|
445
|
-
|
|
446
|
-
|
|
447
|
+
"style-loader",
|
|
448
|
+
"css-loader",
|
|
447
449
|
{
|
|
448
|
-
loader:
|
|
450
|
+
loader: "sass-loader",
|
|
449
451
|
options: {
|
|
450
|
-
additionalData:
|
|
452
|
+
additionalData: "$env: " + process.env.NODE_ENV + ";",
|
|
451
453
|
},
|
|
452
454
|
},
|
|
453
455
|
],
|
|
@@ -459,6 +461,8 @@ module.exports = {
|
|
|
459
461
|
|
|
460
462
|
#### `Function`
|
|
461
463
|
|
|
464
|
+
##### Sync
|
|
465
|
+
|
|
462
466
|
```js
|
|
463
467
|
module.exports = {
|
|
464
468
|
module: {
|
|
@@ -466,21 +470,55 @@ module.exports = {
|
|
|
466
470
|
{
|
|
467
471
|
test: /\.s[ac]ss$/i,
|
|
468
472
|
use: [
|
|
469
|
-
|
|
470
|
-
|
|
473
|
+
"style-loader",
|
|
474
|
+
"css-loader",
|
|
471
475
|
{
|
|
472
|
-
loader:
|
|
476
|
+
loader: "sass-loader",
|
|
473
477
|
options: {
|
|
474
478
|
additionalData: (content, loaderContext) => {
|
|
475
479
|
// More information about available properties https://webpack.js.org/api/loaders/
|
|
476
480
|
const { resourcePath, rootContext } = loaderContext;
|
|
477
481
|
const relativePath = path.relative(rootContext, resourcePath);
|
|
478
482
|
|
|
479
|
-
if (relativePath ===
|
|
480
|
-
return
|
|
483
|
+
if (relativePath === "styles/foo.scss") {
|
|
484
|
+
return "$value: 100px;" + content;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
return "$value: 200px;" + content;
|
|
488
|
+
},
|
|
489
|
+
},
|
|
490
|
+
},
|
|
491
|
+
],
|
|
492
|
+
},
|
|
493
|
+
],
|
|
494
|
+
},
|
|
495
|
+
};
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
##### Async
|
|
499
|
+
|
|
500
|
+
```js
|
|
501
|
+
module.exports = {
|
|
502
|
+
module: {
|
|
503
|
+
rules: [
|
|
504
|
+
{
|
|
505
|
+
test: /\.s[ac]ss$/i,
|
|
506
|
+
use: [
|
|
507
|
+
"style-loader",
|
|
508
|
+
"css-loader",
|
|
509
|
+
{
|
|
510
|
+
loader: "sass-loader",
|
|
511
|
+
options: {
|
|
512
|
+
additionalData: async (content, loaderContext) => {
|
|
513
|
+
// More information about available properties https://webpack.js.org/api/loaders/
|
|
514
|
+
const { resourcePath, rootContext } = loaderContext;
|
|
515
|
+
const relativePath = path.relative(rootContext, resourcePath);
|
|
516
|
+
|
|
517
|
+
if (relativePath === "styles/foo.scss") {
|
|
518
|
+
return "$value: 100px;" + content;
|
|
481
519
|
}
|
|
482
520
|
|
|
483
|
-
return
|
|
521
|
+
return "$value: 200px;" + content;
|
|
484
522
|
},
|
|
485
523
|
},
|
|
486
524
|
},
|
|
@@ -510,10 +548,10 @@ module.exports = {
|
|
|
510
548
|
{
|
|
511
549
|
test: /\.s[ac]ss$/i,
|
|
512
550
|
use: [
|
|
513
|
-
|
|
514
|
-
|
|
551
|
+
"style-loader",
|
|
552
|
+
"css-loader",
|
|
515
553
|
{
|
|
516
|
-
loader:
|
|
554
|
+
loader: "sass-loader",
|
|
517
555
|
options: {
|
|
518
556
|
webpackImporter: false,
|
|
519
557
|
},
|
|
@@ -539,7 +577,7 @@ There are two possibilities to extract a style sheet from the bundle:
|
|
|
539
577
|
**webpack.config.js**
|
|
540
578
|
|
|
541
579
|
```js
|
|
542
|
-
const MiniCssExtractPlugin = require(
|
|
580
|
+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
543
581
|
|
|
544
582
|
module.exports = {
|
|
545
583
|
module: {
|
|
@@ -548,11 +586,11 @@ module.exports = {
|
|
|
548
586
|
test: /\.s[ac]ss$/i,
|
|
549
587
|
use: [
|
|
550
588
|
// fallback to style-loader in development
|
|
551
|
-
process.env.NODE_ENV !==
|
|
552
|
-
?
|
|
589
|
+
process.env.NODE_ENV !== "production"
|
|
590
|
+
? "style-loader"
|
|
553
591
|
: MiniCssExtractPlugin.loader,
|
|
554
|
-
|
|
555
|
-
|
|
592
|
+
"css-loader",
|
|
593
|
+
"sass-loader",
|
|
556
594
|
],
|
|
557
595
|
},
|
|
558
596
|
],
|
|
@@ -561,8 +599,8 @@ module.exports = {
|
|
|
561
599
|
new MiniCssExtractPlugin({
|
|
562
600
|
// Options similar to the same options in webpackOptions.output
|
|
563
601
|
// both options are optional
|
|
564
|
-
filename:
|
|
565
|
-
chunkFilename:
|
|
602
|
+
filename: "[name].css",
|
|
603
|
+
chunkFilename: "[id].css",
|
|
566
604
|
}),
|
|
567
605
|
],
|
|
568
606
|
};
|
|
@@ -578,21 +616,21 @@ To enable CSS source maps, you'll need to pass the `sourceMap` option to the `sa
|
|
|
578
616
|
|
|
579
617
|
```javascript
|
|
580
618
|
module.exports = {
|
|
581
|
-
devtool:
|
|
619
|
+
devtool: "source-map", // any "source-map"-like devtool is possible
|
|
582
620
|
module: {
|
|
583
621
|
rules: [
|
|
584
622
|
{
|
|
585
623
|
test: /\.s[ac]ss$/i,
|
|
586
624
|
use: [
|
|
587
|
-
|
|
625
|
+
"style-loader",
|
|
588
626
|
{
|
|
589
|
-
loader:
|
|
627
|
+
loader: "css-loader",
|
|
590
628
|
options: {
|
|
591
629
|
sourceMap: true,
|
|
592
630
|
},
|
|
593
631
|
},
|
|
594
632
|
{
|
|
595
|
-
loader:
|
|
633
|
+
loader: "sass-loader",
|
|
596
634
|
options: {
|
|
597
635
|
sourceMap: true,
|
|
598
636
|
},
|
package/dist/SassError.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.default = void 0;
|
|
|
8
8
|
class SassError extends Error {
|
|
9
9
|
constructor(sassError) {
|
|
10
10
|
super();
|
|
11
|
-
this.name =
|
|
11
|
+
this.name = "SassError";
|
|
12
12
|
this.originalSassError = sassError;
|
|
13
13
|
this.loc = {
|
|
14
14
|
line: sassError.line,
|
|
@@ -18,7 +18,7 @@ class SassError extends Error {
|
|
|
18
18
|
this.message = `${this.name}: ${this.originalSassError.message}`;
|
|
19
19
|
|
|
20
20
|
if (this.originalSassError.formatted) {
|
|
21
|
-
this.message = `${this.name}: ${this.originalSassError.formatted.replace(/^Error: /,
|
|
21
|
+
this.message = `${this.name}: ${this.originalSassError.formatted.replace(/^Error: /, "")}`; // Instruct webpack to hide the JS stack from the console.
|
|
22
22
|
// Usually you're only interested in the SASS stack in this case.
|
|
23
23
|
|
|
24
24
|
this.hideStack = true;
|
package/dist/cjs.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -25,16 +25,23 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
25
25
|
* @this {object}
|
|
26
26
|
* @param {string} content
|
|
27
27
|
*/
|
|
28
|
-
function loader(content) {
|
|
28
|
+
async function loader(content) {
|
|
29
29
|
const options = (0, _loaderUtils.getOptions)(this);
|
|
30
30
|
(0, _schemaUtils.validate)(_options.default, options, {
|
|
31
|
-
name:
|
|
32
|
-
baseDataPath:
|
|
31
|
+
name: "Sass Loader",
|
|
32
|
+
baseDataPath: "options"
|
|
33
33
|
});
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
const callback = this.async();
|
|
35
|
+
const implementation = (0, _utils.getSassImplementation)(this, options.implementation);
|
|
36
|
+
|
|
37
|
+
if (!implementation) {
|
|
38
|
+
callback();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const useSourceMap = typeof options.sourceMap === "boolean" ? options.sourceMap : this.sourceMap;
|
|
43
|
+
const sassOptions = await (0, _utils.getSassOptions)(this, options, content, implementation, useSourceMap);
|
|
44
|
+
const shouldUseWebpackImporter = typeof options.webpackImporter === "boolean" ? options.webpackImporter : true;
|
|
38
45
|
|
|
39
46
|
if (shouldUseWebpackImporter) {
|
|
40
47
|
const {
|
|
@@ -43,7 +50,6 @@ function loader(content) {
|
|
|
43
50
|
sassOptions.importer.push((0, _utils.getWebpackImporter)(this, implementation, includePaths));
|
|
44
51
|
}
|
|
45
52
|
|
|
46
|
-
const callback = this.async();
|
|
47
53
|
const render = (0, _utils.getRenderFunctionFromSassImplementation)(implementation);
|
|
48
54
|
render(sassOptions, (error, result) => {
|
|
49
55
|
if (error) {
|
|
@@ -64,7 +70,12 @@ function loader(content) {
|
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
result.stats.includedFiles.forEach(includedFile => {
|
|
67
|
-
|
|
73
|
+
const normalizedIncludedFile = _path.default.normalize(includedFile); // Custom `importer` can return only `contents` so includedFile will be relative
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if (_path.default.isAbsolute(normalizedIncludedFile)) {
|
|
77
|
+
this.addDependency(normalizedIncludedFile);
|
|
78
|
+
}
|
|
68
79
|
});
|
|
69
80
|
callback(null, result.css.toString(), map);
|
|
70
81
|
});
|