sass-loader 16.0.8 → 17.0.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 +208 -104
- package/dist/cjs/index.js +82 -0
- package/dist/{options.json → cjs/options.json} +3 -3
- package/dist/cjs/package.json +1 -0
- package/dist/{utils.js → cjs/utils.js} +347 -326
- package/dist/esm/index.js +75 -0
- package/dist/esm/options.json +64 -0
- package/dist/esm/utils.js +743 -0
- package/package.json +55 -66
- package/types/index.d.ts +19 -0
- package/types/utils.d.ts +323 -0
- package/dist/cjs.js +0 -4
- package/dist/index.js +0 -103
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
8
|
+
var _nodeUrl = _interopRequireDefault(require("node:url"));
|
|
9
|
+
var _options = _interopRequireDefault(require("./options.json"));
|
|
10
|
+
var _utils = require("./utils.js");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
/** @typedef {import("webpack").LoaderContext<LoaderOptions>} LoaderContext */
|
|
13
|
+
/** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
|
|
14
|
+
/** @typedef {import("./utils.js").LoaderOptions} LoaderOptions */
|
|
15
|
+
/** @typedef {import("./utils.js").SassError} SassError */
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The sass-loader makes dart-sass and sass-embedded available to webpack modules.
|
|
19
|
+
* @this {LoaderContext}
|
|
20
|
+
* @param {string} content content
|
|
21
|
+
* @returns {Promise<void>} loader result
|
|
22
|
+
*/
|
|
23
|
+
async function loader(content) {
|
|
24
|
+
const options = this.getOptions(/** @type {Schema} */_options.default);
|
|
25
|
+
const callback = this.async();
|
|
26
|
+
let implementation;
|
|
27
|
+
try {
|
|
28
|
+
implementation = await (0, _utils.getSassImplementation)(options.implementation);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
callback(/** @type {Error} */error);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const useSourceMap = typeof options.sourceMap === "boolean" ? options.sourceMap : this.sourceMap === true;
|
|
34
|
+
const sassOptions = await (0, _utils.getSassOptions)(this, options, content, useSourceMap);
|
|
35
|
+
const shouldUseWebpackImporter = typeof options.webpackImporter === "boolean" ? options.webpackImporter : true;
|
|
36
|
+
if (shouldUseWebpackImporter) {
|
|
37
|
+
sassOptions.importers.push((0, _utils.getModernWebpackImporter)(this));
|
|
38
|
+
}
|
|
39
|
+
let compile;
|
|
40
|
+
try {
|
|
41
|
+
compile = (0, _utils.getCompileFn)(this, implementation, options.api);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
callback(/** @type {Error} */error);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
let result;
|
|
47
|
+
try {
|
|
48
|
+
result = await compile(sassOptions);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
const sassError = /** @type {SassError} */error;
|
|
51
|
+
|
|
52
|
+
// There are situations when the `span.url` property does not exist
|
|
53
|
+
if (sassError.span && typeof sassError.span.url !== "undefined") {
|
|
54
|
+
this.addDependency(_nodeUrl.default.fileURLToPath(sassError.span.url));
|
|
55
|
+
}
|
|
56
|
+
callback((0, _utils.errorFactory)(sassError));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
let map = result.sourceMap || undefined;
|
|
60
|
+
|
|
61
|
+
// Modify source paths only for webpack, otherwise we do nothing
|
|
62
|
+
if (map && useSourceMap) {
|
|
63
|
+
map = (0, _utils.normalizeSourceMap)(map, this.rootContext);
|
|
64
|
+
}
|
|
65
|
+
const {
|
|
66
|
+
css,
|
|
67
|
+
map: cssMap
|
|
68
|
+
} = (0, _utils.removeBOM)(result.css.toString(), map);
|
|
69
|
+
if (typeof result.loadedUrls !== "undefined") {
|
|
70
|
+
for (const includedFile of result.loadedUrls.filter(loadedUrl => loadedUrl.protocol === "file:")) {
|
|
71
|
+
const normalizedIncludedFile = _nodeUrl.default.fileURLToPath(includedFile);
|
|
72
|
+
|
|
73
|
+
// Custom `importer` can return only `contents` so includedFile will be relative
|
|
74
|
+
if (_nodePath.default.isAbsolute(normalizedIncludedFile)) {
|
|
75
|
+
this.addDependency(normalizedIncludedFile);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
callback(null, css, cssMap || undefined);
|
|
80
|
+
}
|
|
81
|
+
var _default = exports.default = loader;module.exports = exports.default;
|
|
82
|
+
module.exports.default = exports.default;
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
]
|
|
16
16
|
},
|
|
17
17
|
"api": {
|
|
18
|
-
"description": "Switch between
|
|
18
|
+
"description": "Switch between `auto`, `modern` and `modern-compiler` API for `sass` (`Dart Sass`) and `Sass Embedded` implementations.",
|
|
19
19
|
"link": "https://github.com/webpack/sass-loader#sassoptions",
|
|
20
|
-
"enum": ["
|
|
20
|
+
"enum": ["auto", "modern", "modern-compiler"]
|
|
21
21
|
},
|
|
22
22
|
"sassOptions": {
|
|
23
|
-
"description": "Options for `
|
|
23
|
+
"description": "Options for `sass` (`Dart Sass`) or `sass-embedded` implementation.",
|
|
24
24
|
"link": "https://github.com/webpack/sass-loader#sassoptions",
|
|
25
25
|
"anyOf": [
|
|
26
26
|
{
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|