sass-loader 16.0.8 → 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.
@@ -0,0 +1,71 @@
1
+ import path from "node:path";
2
+ import url from "node:url";
3
+ import schema from "./options.json" with { type: "json" };
4
+ import { errorFactory, getCompileFn, getModernWebpackImporter, getSassImplementation, getSassOptions, normalizeSourceMap } from "./utils.js";
5
+
6
+ /** @typedef {import("webpack").LoaderContext<LoaderOptions>} LoaderContext */
7
+ /** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
8
+ /** @typedef {import("./utils.js").LoaderOptions} LoaderOptions */
9
+ /** @typedef {import("./utils.js").SassError} SassError */
10
+
11
+ /**
12
+ * The sass-loader makes dart-sass and sass-embedded available to webpack modules.
13
+ * @this {LoaderContext}
14
+ * @param {string} content content
15
+ * @returns {Promise<void>} loader result
16
+ */
17
+ async function loader(content) {
18
+ const options = this.getOptions(/** @type {Schema} */schema);
19
+ const callback = this.async();
20
+ let implementation;
21
+ try {
22
+ implementation = await getSassImplementation(options.implementation);
23
+ } catch (error) {
24
+ callback(/** @type {Error} */error);
25
+ return;
26
+ }
27
+ const useSourceMap = typeof options.sourceMap === "boolean" ? options.sourceMap : this.sourceMap === true;
28
+ const sassOptions = await getSassOptions(this, options, content, useSourceMap);
29
+ const shouldUseWebpackImporter = typeof options.webpackImporter === "boolean" ? options.webpackImporter : true;
30
+ if (shouldUseWebpackImporter) {
31
+ sassOptions.importers.push(getModernWebpackImporter(this));
32
+ }
33
+ let compile;
34
+ try {
35
+ compile = getCompileFn(this, implementation, options.api);
36
+ } catch (error) {
37
+ callback(/** @type {Error} */error);
38
+ return;
39
+ }
40
+ let result;
41
+ try {
42
+ result = await compile(sassOptions);
43
+ } catch (error) {
44
+ const sassError = /** @type {SassError} */error;
45
+
46
+ // There are situations when the `span.url` property does not exist
47
+ if (sassError.span && typeof sassError.span.url !== "undefined") {
48
+ this.addDependency(url.fileURLToPath(sassError.span.url));
49
+ }
50
+ callback(errorFactory(sassError));
51
+ return;
52
+ }
53
+ let map = result.sourceMap || undefined;
54
+
55
+ // Modify source paths only for webpack, otherwise we do nothing
56
+ if (map && useSourceMap) {
57
+ map = normalizeSourceMap(map, this.rootContext);
58
+ }
59
+ if (typeof result.loadedUrls !== "undefined") {
60
+ for (const includedFile of result.loadedUrls.filter(loadedUrl => loadedUrl.protocol === "file:")) {
61
+ const normalizedIncludedFile = url.fileURLToPath(includedFile);
62
+
63
+ // Custom `importer` can return only `contents` so includedFile will be relative
64
+ if (path.isAbsolute(normalizedIncludedFile)) {
65
+ this.addDependency(normalizedIncludedFile);
66
+ }
67
+ }
68
+ }
69
+ callback(null, result.css.toString(), map || undefined);
70
+ }
71
+ export default loader;
@@ -0,0 +1,64 @@
1
+ {
2
+ "title": "Sass Loader options",
3
+ "type": "object",
4
+ "properties": {
5
+ "implementation": {
6
+ "description": "The implementation of the sass to be used.",
7
+ "link": "https://github.com/webpack/sass-loader#implementation",
8
+ "anyOf": [
9
+ {
10
+ "type": "string"
11
+ },
12
+ {
13
+ "type": "object"
14
+ }
15
+ ]
16
+ },
17
+ "api": {
18
+ "description": "Switch between `auto`, `modern` and `modern-compiler` API for `sass` (`Dart Sass`) and `Sass Embedded` implementations.",
19
+ "link": "https://github.com/webpack/sass-loader#sassoptions",
20
+ "enum": ["auto", "modern", "modern-compiler"]
21
+ },
22
+ "sassOptions": {
23
+ "description": "Options for `sass` (`Dart Sass`) or `sass-embedded` implementation.",
24
+ "link": "https://github.com/webpack/sass-loader#sassoptions",
25
+ "anyOf": [
26
+ {
27
+ "type": "object",
28
+ "additionalProperties": true
29
+ },
30
+ {
31
+ "instanceof": "Function"
32
+ }
33
+ ]
34
+ },
35
+ "additionalData": {
36
+ "description": "Prepends/Appends `Sass`/`SCSS` code before the actual entry file.",
37
+ "link": "https://github.com/webpack/sass-loader#additionaldata",
38
+ "anyOf": [
39
+ {
40
+ "type": "string"
41
+ },
42
+ {
43
+ "instanceof": "Function"
44
+ }
45
+ ]
46
+ },
47
+ "sourceMap": {
48
+ "description": "Enables/Disables generation of source maps.",
49
+ "link": "https://github.com/webpack/sass-loader#sourcemap",
50
+ "type": "boolean"
51
+ },
52
+ "webpackImporter": {
53
+ "description": "Enables/Disables default `webpack` importer.",
54
+ "link": "https://github.com/webpack/sass-loader#webpackimporter",
55
+ "type": "boolean"
56
+ },
57
+ "warnRuleAsWarning": {
58
+ "description": "Treats the '@warn' rule as a webpack warning.",
59
+ "link": "https://github.com/webpack/sass-loader#warnruleaswarning",
60
+ "type": "boolean"
61
+ }
62
+ },
63
+ "additionalProperties": false
64
+ }