sass-loader 8.0.1 → 9.0.2
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 +46 -0
- package/README.md +83 -57
- package/dist/SassError.js +2 -3
- package/dist/index.js +19 -50
- package/dist/options.json +2 -2
- package/dist/utils.js +379 -0
- package/package.json +34 -37
- package/dist/getDefaultSassImplementation.js +0 -28
- package/dist/getRenderFunctionFromSassImplementation.js +0 -39
- package/dist/getSassImplementation.js +0 -56
- package/dist/getSassOptions.js +0 -116
- package/dist/importsToResolve.js +0 -88
- package/dist/proxyCustomImporters.js +0 -31
- package/dist/webpackImporter.js +0 -75
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,52 @@
|
|
|
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
|
+
### [9.0.2](https://github.com/webpack-contrib/sass-loader/compare/v9.0.1...v9.0.2) (2020-07-07)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* resolution algorithm for `node-sass` ([#866](https://github.com/webpack-contrib/sass-loader/issues/866)) ([4584c90](https://github.com/webpack-contrib/sass-loader/commit/4584c9054befbc56661e2781a55df96fb9f94673))
|
|
11
|
+
|
|
12
|
+
### [9.0.1](https://github.com/webpack-contrib/sass-loader/compare/v9.0.0...v9.0.1) (2020-07-03)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* do not crash on errors ([#860](https://github.com/webpack-contrib/sass-loader/issues/860)) ([e854933](https://github.com/webpack-contrib/sass-loader/commit/e8549330f8d9373ff8baccffbfd3e0c3b6f3ef61))
|
|
18
|
+
|
|
19
|
+
## [9.0.0](https://github.com/webpack-contrib/sass-loader/compare/v8.0.2...v9.0.0) (2020-07-02)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### ⚠ BREAKING CHANGES
|
|
23
|
+
|
|
24
|
+
* minimum supported Nodejs version is `10.13`
|
|
25
|
+
* prefer `sass` (`dart-sass`) by default, it is strongly recommended to migrate on `sass` (`dart-sass`)
|
|
26
|
+
* the `prependData` option was removed in favor the `additionalData` option, see [docs](https://github.com/webpack-contrib/sass-loader#additionaldata)
|
|
27
|
+
* when the `sourceMap` is `true`, `sassOptions.sourceMap`, `sassOptions.sourceMapContents`, `sassOptions.sourceMapEmbed`, `sassOptions.sourceMapRoot` and `sassOptions.omitSourceMapUrl` will be ignored.
|
|
28
|
+
|
|
29
|
+
### Features
|
|
30
|
+
|
|
31
|
+
* pass the loader context to custom importers under the `this.webpackLoaderContext` property ([#853](https://github.com/webpack-contrib/sass-loader/issues/853)) ([d487683](https://github.com/webpack-contrib/sass-loader/commit/d487683221fcd1e5a173e083b4b40644751c8cb1))
|
|
32
|
+
* supports for `process.cwd()` resolution logic by default ([#837](https://github.com/webpack-contrib/sass-loader/issues/837)) ([0c8d3b3](https://github.com/webpack-contrib/sass-loader/commit/0c8d3b3fb1cf371779b4a886cfc4e60facf68759))
|
|
33
|
+
* supports for `SASS-PATH` env variable resolution logic by default ([#836](https://github.com/webpack-contrib/sass-loader/issues/836)) ([8376179](https://github.com/webpack-contrib/sass-loader/commit/83761798380dcccc5a2badde3b3affe2bac385e8))
|
|
34
|
+
* supports for the `sass` property for the `exports` field from `package.json` (conditional exports, for more information read [docs](https://nodejs.org/api/esm.html))
|
|
35
|
+
|
|
36
|
+
### Bug Fixes
|
|
37
|
+
|
|
38
|
+
* avoid different content on different os ([#832](https://github.com/webpack-contrib/sass-loader/issues/832)) ([68dd278](https://github.com/webpack-contrib/sass-loader/commit/68dd27883ce0536adc5bc170816242c67fb118ff))
|
|
39
|
+
* resolution logic when the `includePaths` option used was improved ([#827](https://github.com/webpack-contrib/sass-loader/issues/827)) ([cbe5ad4](https://github.com/webpack-contrib/sass-loader/commit/cbe5ad407582a617be097d3eadd3ad8619e52507))
|
|
40
|
+
* resolution logic for `file://` scheme was improved ([17832fd](https://github.com/webpack-contrib/sass-loader/commit/17832fdb11f91593f4e2995003d67aebefb3be90))
|
|
41
|
+
* resolution logic for absolute paths and server relative URLs was improved
|
|
42
|
+
* source maps generation was improved
|
|
43
|
+
|
|
44
|
+
### [8.0.2](https://github.com/webpack-contrib/sass-loader/compare/v8.0.1...v8.0.2) (2020-01-13)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
### Bug Fixes
|
|
48
|
+
|
|
49
|
+
* compatibility with node@8 ([#798](https://github.com/webpack-contrib/sass-loader/issues/798)) ([6f3852f](https://github.com/webpack-contrib/sass-loader/commit/6f3852f7d393dd0bc8f8d264d81ecc941bc72511))
|
|
50
|
+
|
|
5
51
|
### [8.0.1](https://github.com/webpack-contrib/sass-loader/compare/v8.0.0...v8.0.1) (2020-01-10)
|
|
6
52
|
|
|
7
53
|
|
package/README.md
CHANGED
|
@@ -24,12 +24,17 @@ Loads a Sass/SCSS file and compiles it to CSS.
|
|
|
24
24
|
To begin, you'll need to install `sass-loader`:
|
|
25
25
|
|
|
26
26
|
```console
|
|
27
|
-
npm install sass-loader
|
|
27
|
+
npm install sass-loader sass webpack --save-dev
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
`sass-loader` requires you to install either [
|
|
30
|
+
`sass-loader` requires you to install either [Dart Sass](https://github.com/sass/dart-sass) or [Node Sass](https://github.com/sass/node-sass) on your own (more documentation can be found below).
|
|
31
|
+
|
|
31
32
|
This allows you to control the versions of all your dependencies, and to choose which Sass implementation to use.
|
|
32
33
|
|
|
34
|
+
> ℹ️ We recommend using [Dart Sass](https://github.com/sass/dart-sass).
|
|
35
|
+
|
|
36
|
+
> ⚠ [Node Sass](https://github.com/sass/node-sass) does not work with [Yarn PnP](https://classic.yarnpkg.com/en/docs/pnp/) feature.
|
|
37
|
+
|
|
33
38
|
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.
|
|
34
39
|
|
|
35
40
|
Then add the loader to your Webpack configuration. For example:
|
|
@@ -104,12 +109,23 @@ Thankfully there are a two solutions to this problem:
|
|
|
104
109
|
|
|
105
110
|
## Options
|
|
106
111
|
|
|
112
|
+
| Name | Type | Default | Description |
|
|
113
|
+
| :---------------------------------------: | :------------------: | :-------------------------------------: | :---------------------------------------------------------------- |
|
|
114
|
+
| **[`implementation`](#implementation)** | `{Object}` | `sass` | Setup Sass implementation to use. |
|
|
115
|
+
| **[`sassOptions`](#sassoptions)** | `{Object\|Function}` | defaults values for Sass implementation | Options for Sass. |
|
|
116
|
+
| **[`sourceMap`](#sourcemap)** | `{Boolean}` | `compiler.devtool` | Enables/Disables generation of source maps. |
|
|
117
|
+
| **[`additionalData`](#additionaldata)** | `{String\|Function}` | `undefined` | Prepends/Appends `Sass`/`SCSS` code before the actual entry file. |
|
|
118
|
+
| **[`webpackImporter`](#webpackimporter)** | `{Boolean}` | `true` | Enables/Disables the default Webpack importer. |
|
|
119
|
+
|
|
107
120
|
### `implementation`
|
|
108
121
|
|
|
122
|
+
Type: `Object`
|
|
123
|
+
Default: `sass`
|
|
124
|
+
|
|
109
125
|
The special `implementation` option determines which implementation of Sass to use.
|
|
110
126
|
|
|
111
127
|
By default the loader resolve the implementation based on your dependencies.
|
|
112
|
-
Just add required implementation to `package.json` (`
|
|
128
|
+
Just add required implementation to `package.json` (`sass` or `node-sass` package) and install dependencies.
|
|
113
129
|
|
|
114
130
|
Example where the `sass-loader` loader uses the `sass` (`dart-sass`) implementation:
|
|
115
131
|
|
|
@@ -137,9 +153,10 @@ Example where the `sass-loader` loader uses the `node-sass` implementation:
|
|
|
137
153
|
}
|
|
138
154
|
```
|
|
139
155
|
|
|
140
|
-
Beware the situation when `node-sass` and `sass` were installed! By default the `sass-loader` prefers `
|
|
156
|
+
Beware the situation when `node-sass` and `sass` were installed! By default the `sass-loader` prefers `sass`.
|
|
157
|
+
In order to avoid this situation you can use the `implementation` option.
|
|
141
158
|
|
|
142
|
-
The `implementation` options either accepts `
|
|
159
|
+
The `implementation` options either accepts `sass` (`Dart Sass`) or `node-sass` as a module.
|
|
143
160
|
|
|
144
161
|
For example, to use Dart Sass, you'd pass:
|
|
145
162
|
|
|
@@ -244,20 +261,24 @@ module.exports = {
|
|
|
244
261
|
### `sassOptions`
|
|
245
262
|
|
|
246
263
|
Type: `Object|Function`
|
|
264
|
+
Default: defaults values for Sass implementation
|
|
247
265
|
|
|
248
|
-
Options for [
|
|
266
|
+
Options for [Dart Sass](http://sass-lang.com/dart-sass) or [Node Sass](https://github.com/sass/node-sass) implementation.
|
|
249
267
|
|
|
250
268
|
> ℹ️ The `indentedSyntax` option has `true` value for the `sass` extension.
|
|
251
269
|
|
|
252
|
-
> ℹ️ Options such as `
|
|
270
|
+
> ℹ️ Options such as `data` and `file` are unavailable and will be ignored.
|
|
253
271
|
|
|
254
|
-
> ℹ We recommend not to
|
|
272
|
+
> ℹ We recommend not to set the `outFile`, `sourceMapContents`, `sourceMapEmbed`, `sourceMapRoot` options because `sass-loader` automatically sets these options when the `sourceMap` option is `true`.
|
|
273
|
+
|
|
274
|
+
> ℹ️ 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.
|
|
275
|
+
|
|
276
|
+
There is a slight difference between the `sass` (`dart-sass`) and `node-sass` options.
|
|
255
277
|
|
|
256
|
-
There is a slight difference between the `node-sass` and `sass` (`Dart Sass`) options.
|
|
257
278
|
Please consult documentation before using them:
|
|
258
279
|
|
|
259
|
-
- [Node Sass documentation](https://github.com/sass/node-sass/#options) for all available `node-sass` options.
|
|
260
280
|
- [Dart Sass documentation](https://github.com/sass/dart-sass#javascript-api) for all available `sass` options.
|
|
281
|
+
- [Node Sass documentation](https://github.com/sass/node-sass/#options) for all available `node-sass` options.
|
|
261
282
|
|
|
262
283
|
#### `Object`
|
|
263
284
|
|
|
@@ -330,19 +351,19 @@ module.exports = {
|
|
|
330
351
|
};
|
|
331
352
|
```
|
|
332
353
|
|
|
333
|
-
### `
|
|
354
|
+
### `sourceMap`
|
|
334
355
|
|
|
335
|
-
Type: `
|
|
336
|
-
Default: `
|
|
356
|
+
Type: `Boolean`
|
|
357
|
+
Default: depends on the `compiler.devtool` value
|
|
337
358
|
|
|
338
|
-
|
|
339
|
-
In this case, the `sass-loader` will not override the `data` option but just append the entry's content.
|
|
359
|
+
Enables/Disables generation of source maps.
|
|
340
360
|
|
|
341
|
-
|
|
361
|
+
By default generation of source maps depends on the [`devtool`](https://webpack.js.org/configuration/devtool/) option.
|
|
362
|
+
All values enable source map generation except `eval` and `false` value.
|
|
342
363
|
|
|
343
|
-
> ℹ
|
|
364
|
+
> ℹ If a `true` the `sourceMap`, `sourceMapRoot`, `sourceMapEmbed`, `sourceMapContents` and `omitSourceMapUrl` from `sassOptions` will be ignored.
|
|
344
365
|
|
|
345
|
-
|
|
366
|
+
**webpack.config.js**
|
|
346
367
|
|
|
347
368
|
```js
|
|
348
369
|
module.exports = {
|
|
@@ -352,11 +373,16 @@ module.exports = {
|
|
|
352
373
|
test: /\.s[ac]ss$/i,
|
|
353
374
|
use: [
|
|
354
375
|
'style-loader',
|
|
355
|
-
|
|
376
|
+
{
|
|
377
|
+
loader: 'css-loader',
|
|
378
|
+
options: {
|
|
379
|
+
sourceMap: true,
|
|
380
|
+
},
|
|
381
|
+
},
|
|
356
382
|
{
|
|
357
383
|
loader: 'sass-loader',
|
|
358
384
|
options: {
|
|
359
|
-
|
|
385
|
+
sourceMap: true,
|
|
360
386
|
},
|
|
361
387
|
},
|
|
362
388
|
],
|
|
@@ -366,7 +392,11 @@ module.exports = {
|
|
|
366
392
|
};
|
|
367
393
|
```
|
|
368
394
|
|
|
369
|
-
|
|
395
|
+
> ℹ In some rare cases `node-sass` can output invalid source maps (it is a `node-sass` bug).
|
|
396
|
+
|
|
397
|
+
> > 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`.
|
|
398
|
+
|
|
399
|
+
**webpack.config.js**
|
|
370
400
|
|
|
371
401
|
```js
|
|
372
402
|
module.exports = {
|
|
@@ -380,16 +410,9 @@ module.exports = {
|
|
|
380
410
|
{
|
|
381
411
|
loader: 'sass-loader',
|
|
382
412
|
options: {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
const relativePath = path.relative(rootContext, resourcePath);
|
|
387
|
-
|
|
388
|
-
if (relativePath === 'styles/foo.scss') {
|
|
389
|
-
return '$value: 100px;';
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
return '$value: 200px;';
|
|
413
|
+
sourceMap: true,
|
|
414
|
+
sassOptions: {
|
|
415
|
+
outputStyle: 'compressed',
|
|
393
416
|
},
|
|
394
417
|
},
|
|
395
418
|
},
|
|
@@ -400,16 +423,17 @@ module.exports = {
|
|
|
400
423
|
};
|
|
401
424
|
```
|
|
402
425
|
|
|
403
|
-
### `
|
|
426
|
+
### `additionalData`
|
|
404
427
|
|
|
405
|
-
Type: `
|
|
406
|
-
Default:
|
|
428
|
+
Type: `String|Function`
|
|
429
|
+
Default: `undefined`
|
|
407
430
|
|
|
408
|
-
|
|
431
|
+
Prepends `Sass`/`SCSS` code before the actual entry file.
|
|
432
|
+
In this case, the `sass-loader` will not override the `data` option but just **prepend** the entry's content.
|
|
409
433
|
|
|
410
|
-
|
|
434
|
+
This is especially useful when some of your Sass variables depend on the environment:
|
|
411
435
|
|
|
412
|
-
|
|
436
|
+
#### `String`
|
|
413
437
|
|
|
414
438
|
```js
|
|
415
439
|
module.exports = {
|
|
@@ -419,16 +443,11 @@ module.exports = {
|
|
|
419
443
|
test: /\.s[ac]ss$/i,
|
|
420
444
|
use: [
|
|
421
445
|
'style-loader',
|
|
422
|
-
|
|
423
|
-
loader: 'css-loader',
|
|
424
|
-
options: {
|
|
425
|
-
sourceMap: true,
|
|
426
|
-
},
|
|
427
|
-
},
|
|
446
|
+
'css-loader',
|
|
428
447
|
{
|
|
429
448
|
loader: 'sass-loader',
|
|
430
449
|
options: {
|
|
431
|
-
|
|
450
|
+
additionalData: '$env: ' + process.env.NODE_ENV + ';',
|
|
432
451
|
},
|
|
433
452
|
},
|
|
434
453
|
],
|
|
@@ -438,10 +457,7 @@ module.exports = {
|
|
|
438
457
|
};
|
|
439
458
|
```
|
|
440
459
|
|
|
441
|
-
|
|
442
|
-
> 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`.
|
|
443
|
-
|
|
444
|
-
**webpack.config.js**
|
|
460
|
+
#### `Function`
|
|
445
461
|
|
|
446
462
|
```js
|
|
447
463
|
module.exports = {
|
|
@@ -454,9 +470,18 @@ module.exports = {
|
|
|
454
470
|
'css-loader',
|
|
455
471
|
{
|
|
456
472
|
loader: 'sass-loader',
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
473
|
+
options: {
|
|
474
|
+
additionalData: (content, loaderContext) => {
|
|
475
|
+
// More information about available properties https://webpack.js.org/api/loaders/
|
|
476
|
+
const { resourcePath, rootContext } = loaderContext;
|
|
477
|
+
const relativePath = path.relative(rootContext, resourcePath);
|
|
478
|
+
|
|
479
|
+
if (relativePath === 'styles/foo.scss') {
|
|
480
|
+
return '$value: 100px;' + content;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
return '$value: 200px;' + content;
|
|
484
|
+
},
|
|
460
485
|
},
|
|
461
486
|
},
|
|
462
487
|
],
|
|
@@ -473,7 +498,8 @@ Default: `true`
|
|
|
473
498
|
|
|
474
499
|
Enables/Disables the default Webpack importer.
|
|
475
500
|
|
|
476
|
-
This can improve performance in some cases. Use it with caution because aliases and `@import` at-rules starting with `~` will not work.
|
|
501
|
+
This can improve performance in some cases. Use it with caution because aliases and `@import` at-rules starting with `~` will not work.
|
|
502
|
+
You can pass own `importer` to solve this (see [`importer docs`](https://github.com/sass/node-sass#importer--v200---experimental)).
|
|
477
503
|
|
|
478
504
|
**webpack.config.js**
|
|
479
505
|
|
|
@@ -556,7 +582,7 @@ module.exports = {
|
|
|
556
582
|
module: {
|
|
557
583
|
rules: [
|
|
558
584
|
{
|
|
559
|
-
test: /\.
|
|
585
|
+
test: /\.s[ac]ss$/i,
|
|
560
586
|
use: [
|
|
561
587
|
'style-loader',
|
|
562
588
|
{
|
|
@@ -596,11 +622,11 @@ Please take a moment to read our contributing guidelines if you haven't yet done
|
|
|
596
622
|
[node-url]: https://nodejs.org
|
|
597
623
|
[deps]: https://david-dm.org/webpack-contrib/sass-loader.svg
|
|
598
624
|
[deps-url]: https://david-dm.org/webpack-contrib/sass-loader
|
|
599
|
-
[tests]: https://
|
|
600
|
-
[tests-url]: https://
|
|
625
|
+
[tests]: https://github.com/webpack-contrib/sass-loader/workflows/sass-loader/badge.svg
|
|
626
|
+
[tests-url]: https://github.com/webpack-contrib/sass-loader/actions
|
|
601
627
|
[cover]: https://codecov.io/gh/webpack-contrib/sass-loader/branch/master/graph/badge.svg
|
|
602
628
|
[cover-url]: https://codecov.io/gh/webpack-contrib/sass-loader
|
|
603
629
|
[chat]: https://badges.gitter.im/webpack/webpack.svg
|
|
604
630
|
[chat-url]: https://gitter.im/webpack/webpack
|
|
605
|
-
[size]: https://packagephobia.now.sh/badge?p=
|
|
606
|
-
[size-url]: https://packagephobia.now.sh/result?p=
|
|
631
|
+
[size]: https://packagephobia.now.sh/badge?p=sass-loader
|
|
632
|
+
[size-url]: https://packagephobia.now.sh/result?p=sass-loader
|
package/dist/SassError.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
class SassError extends Error {
|
|
9
|
-
constructor(sassError
|
|
9
|
+
constructor(sassError) {
|
|
10
10
|
super();
|
|
11
11
|
this.name = 'SassError';
|
|
12
12
|
this.originalSassError = sassError;
|
|
@@ -18,9 +18,8 @@ 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
|
-
// eslint-disable-next-line no-param-reassign
|
|
24
23
|
|
|
25
24
|
this.hideStack = true;
|
|
26
25
|
Error.captureStackTrace(this, this.constructor);
|
package/dist/index.js
CHANGED
|
@@ -13,13 +13,7 @@ var _loaderUtils = require("loader-utils");
|
|
|
13
13
|
|
|
14
14
|
var _options = _interopRequireDefault(require("./options.json"));
|
|
15
15
|
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
var _getSassOptions = _interopRequireDefault(require("./getSassOptions"));
|
|
19
|
-
|
|
20
|
-
var _webpackImporter = _interopRequireDefault(require("./webpackImporter"));
|
|
21
|
-
|
|
22
|
-
var _getRenderFunctionFromSassImplementation = _interopRequireDefault(require("./getRenderFunctionFromSassImplementation"));
|
|
16
|
+
var _utils = require("./utils");
|
|
23
17
|
|
|
24
18
|
var _SassError = _interopRequireDefault(require("./SassError"));
|
|
25
19
|
|
|
@@ -32,80 +26,55 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
32
26
|
* @param {string} content
|
|
33
27
|
*/
|
|
34
28
|
function loader(content) {
|
|
35
|
-
const options = (0, _loaderUtils.getOptions)(this)
|
|
29
|
+
const options = (0, _loaderUtils.getOptions)(this);
|
|
36
30
|
(0, _schemaUtils.default)(_options.default, options, {
|
|
37
31
|
name: 'Sass Loader',
|
|
38
32
|
baseDataPath: 'options'
|
|
39
33
|
});
|
|
40
|
-
const implementation = (0,
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
const addNormalizedDependency = file => {
|
|
44
|
-
// node-sass returns POSIX paths
|
|
45
|
-
this.addDependency(_path.default.normalize(file));
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const sassOptions = (0, _getSassOptions.default)(this, options, content, implementation);
|
|
34
|
+
const implementation = (0, _utils.getSassImplementation)(options.implementation);
|
|
35
|
+
const sassOptions = (0, _utils.getSassOptions)(this, options, content, implementation);
|
|
49
36
|
const shouldUseWebpackImporter = typeof options.webpackImporter === 'boolean' ? options.webpackImporter : true;
|
|
50
37
|
|
|
51
38
|
if (shouldUseWebpackImporter) {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
57
|
-
sassOptions.importer.push((0, _webpackImporter.default)(this.resourcePath, resolve, addNormalizedDependency));
|
|
58
|
-
} // Skip empty files, otherwise it will stop webpack, see issue #21
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (sassOptions.data.trim() === '') {
|
|
62
|
-
callback(null, '');
|
|
63
|
-
return;
|
|
39
|
+
const {
|
|
40
|
+
includePaths
|
|
41
|
+
} = sassOptions;
|
|
42
|
+
sassOptions.importer.push((0, _utils.getWebpackImporter)(this, implementation, includePaths));
|
|
64
43
|
}
|
|
65
44
|
|
|
66
|
-
const
|
|
45
|
+
const callback = this.async();
|
|
46
|
+
const render = (0, _utils.getRenderFunctionFromSassImplementation)(implementation);
|
|
67
47
|
render(sassOptions, (error, result) => {
|
|
68
48
|
if (error) {
|
|
49
|
+
// There are situations when the `file` property do not exist
|
|
69
50
|
if (error.file) {
|
|
70
|
-
|
|
51
|
+
// `node-sass` returns POSIX paths
|
|
52
|
+
this.addDependency(_path.default.normalize(error.file));
|
|
71
53
|
}
|
|
72
54
|
|
|
73
|
-
callback(new _SassError.default(error
|
|
55
|
+
callback(new _SassError.default(error));
|
|
74
56
|
return;
|
|
75
57
|
}
|
|
76
58
|
|
|
77
|
-
if (result.map
|
|
59
|
+
if (result.map) {
|
|
78
60
|
// eslint-disable-next-line no-param-reassign
|
|
79
61
|
result.map = JSON.parse(result.map); // result.map.file is an optional property that provides the output filename.
|
|
80
62
|
// Since we don't know the final filename in the webpack build chain yet, it makes no sense to have it.
|
|
81
63
|
// eslint-disable-next-line no-param-reassign
|
|
82
64
|
|
|
83
|
-
delete result.map.file; //
|
|
84
|
-
// Now let's override that value with the correct relative path.
|
|
85
|
-
// Since we specified options.sourceMap = path.join(process.cwd(), "/sass.map"); in getSassOptions,
|
|
86
|
-
// we know that this path is relative to process.cwd(). This is how node-sass works.
|
|
87
|
-
// eslint-disable-next-line no-param-reassign
|
|
88
|
-
|
|
89
|
-
const stdinIndex = result.map.sources.findIndex(source => source.includes('stdin'));
|
|
90
|
-
|
|
91
|
-
if (stdinIndex !== -1) {
|
|
92
|
-
// eslint-disable-next-line no-param-reassign
|
|
93
|
-
result.map.sources[stdinIndex] = _path.default.relative(process.cwd(), this.resourcePath);
|
|
94
|
-
} // node-sass returns POSIX paths, that's why we need to transform them back to native paths.
|
|
65
|
+
delete result.map.file; // node-sass returns POSIX paths, that's why we need to transform them back to native paths.
|
|
95
66
|
// This fixes an error on windows where the source-map module cannot resolve the source maps.
|
|
96
67
|
// @see https://github.com/webpack-contrib/sass-loader/issues/366#issuecomment-279460722
|
|
97
68
|
// eslint-disable-next-line no-param-reassign
|
|
98
69
|
|
|
99
|
-
|
|
100
70
|
result.map.sourceRoot = _path.default.normalize(result.map.sourceRoot); // eslint-disable-next-line no-param-reassign
|
|
101
71
|
|
|
102
72
|
result.map.sources = result.map.sources.map(_path.default.normalize);
|
|
103
|
-
} else {
|
|
104
|
-
// eslint-disable-next-line no-param-reassign
|
|
105
|
-
result.map = null;
|
|
106
73
|
}
|
|
107
74
|
|
|
108
|
-
result.stats.includedFiles.forEach(
|
|
75
|
+
result.stats.includedFiles.forEach(includedFile => {
|
|
76
|
+
this.addDependency(_path.default.normalize(includedFile));
|
|
77
|
+
});
|
|
109
78
|
callback(null, result.css.toString(), result.map);
|
|
110
79
|
});
|
|
111
80
|
}
|
package/dist/options.json
CHANGED
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
}
|
|
18
18
|
]
|
|
19
19
|
},
|
|
20
|
-
"
|
|
21
|
-
"description": "Prepends `Sass`/`SCSS` code before the actual entry file (https://github.com/webpack-contrib/sass-loader#
|
|
20
|
+
"additionalData": {
|
|
21
|
+
"description": "Prepends/Appends `Sass`/`SCSS` code before the actual entry file (https://github.com/webpack-contrib/sass-loader#additionaldata).",
|
|
22
22
|
"anyOf": [
|
|
23
23
|
{
|
|
24
24
|
"type": "string"
|