sass-loader 12.0.0 → 12.4.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() {
@@ -56,6 +58,17 @@ function getSassImplementation(loaderContext, implementation) {
56
58
  }
57
59
  }
58
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
+
59
72
  const {
60
73
  info
61
74
  } = resolvedImplementation;
@@ -185,6 +198,57 @@ async function getSassOptions(loaderContext, loaderOptions, content, implementat
185
198
  options.importer = options.importer ? proxyCustomImporters(Array.isArray(options.importer) ? options.importer : [options.importer], loaderContext) : [];
186
199
  options.includePaths = [].concat(process.cwd()).concat( // We use `includePaths` in context for resolver, so it should be always absolute
187
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
+
188
252
  return options;
189
253
  }
190
254
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sass-loader",
3
- "version": "12.0.0",
3
+ "version": "12.4.0",
4
4
  "description": "Sass loader for webpack",
5
5
  "license": "MIT",
6
6
  "repository": "webpack-contrib/sass-loader",
@@ -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:**\"",
@@ -39,7 +39,7 @@
39
39
  ],
40
40
  "peerDependencies": {
41
41
  "fibers": ">= 3.1.0",
42
- "node-sass": "^4.0.0 || ^5.0.0 || ^6.0.0",
42
+ "node-sass": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0",
43
43
  "sass": "^1.3.0",
44
44
  "webpack": "^5.0.0"
45
45
  },
@@ -59,41 +59,41 @@
59
59
  "neo-async": "^2.6.2"
60
60
  },
61
61
  "devDependencies": {
62
- "@babel/cli": "^7.14.3",
63
- "@babel/core": "^7.14.3",
64
- "@babel/preset-env": "^7.14.2",
65
- "@commitlint/cli": "^12.1.4",
66
- "@commitlint/config-conventional": "^12.1.4",
62
+ "@babel/cli": "^7.14.5",
63
+ "@babel/core": "^7.14.6",
64
+ "@babel/preset-env": "^7.14.7",
65
+ "@commitlint/cli": "^15.0.0",
66
+ "@commitlint/config-conventional": "^15.0.0",
67
67
  "@webpack-contrib/eslint-config-webpack": "^3.0.0",
68
- "babel-jest": "^27.0.1",
68
+ "babel-jest": "^27.0.6",
69
69
  "bootstrap-sass": "^3.4.1",
70
70
  "bootstrap-v4": "npm:bootstrap@^4.5.3",
71
71
  "bootstrap-v5": "npm:bootstrap@^5.0.1",
72
72
  "cross-env": "^7.0.3",
73
- "css-loader": "^5.2.6",
73
+ "css-loader": "^6.2.0",
74
74
  "del": "^6.0.0",
75
- "del-cli": "^3.0.1",
75
+ "del-cli": "^4.0.1",
76
76
  "enhanced-resolve": "^5.8.2",
77
- "eslint": "^7.27.0",
77
+ "eslint": "^8.1.0",
78
78
  "eslint-config-prettier": "^8.3.0",
79
79
  "eslint-plugin-import": "^2.23.3",
80
80
  "fibers": "^5.0.0",
81
81
  "file-loader": "^6.2.0",
82
82
  "foundation-sites": "^6.6.3",
83
- "husky": "^6.0.0",
84
- "jest": "^27.0.1",
85
- "lint-staged": "^11.0.0",
83
+ "husky": "^7.0.1",
84
+ "jest": "^27.0.6",
85
+ "lint-staged": "^12.1.2",
86
86
  "material-components-web": "^8.0.0",
87
87
  "memfs": "^3.2.2",
88
- "node-sass": "^6.0.0",
88
+ "node-sass": "^7.0.0",
89
89
  "node-sass-glob-importer": "^5.3.2",
90
90
  "npm-run-all": "^4.1.5",
91
- "prettier": "^2.3.0",
92
- "sass": "^1.34.0",
91
+ "prettier": "^2.3.2",
92
+ "sass": "^1.35.2",
93
93
  "semver": "^7.3.5",
94
- "standard-version": "^9.3.0",
95
- "style-loader": "^2.0.0",
96
- "webpack": "^5.37.1"
94
+ "standard-version": "^9.3.1",
95
+ "style-loader": "^3.2.1",
96
+ "webpack": "^5.45.1"
97
97
  },
98
98
  "keywords": [
99
99
  "sass",