MCPcopy
hub / github.com/webpack/sass-loader / loader

Function loader

src/index.js:25–106  ·  view source on GitHub ↗

* The sass-loader makes dart-sass and sass-embedded available to webpack modules. * @this {LoaderContext} * @param {string} content content * @returns {Promise } loader result

(content)

Source from the content-addressed store, hash-verified

23 * @returns {Promise<void>} loader result
24 */
25async function loader(content) {
26 const options = this.getOptions(/** @type {Schema} */ (schema));
27 const callback = this.async();
28
29 let implementation;
30
31 try {
32 implementation = await getSassImplementation(options.implementation);
33 } catch (error) {
34 callback(/** @type {Error} */ (error));
35
36 return;
37 }
38
39 const useSourceMap =
40 typeof options.sourceMap === "boolean"
41 ? options.sourceMap
42 : this.sourceMap === true;
43 const sassOptions = await getSassOptions(
44 this,
45 options,
46 content,
47 useSourceMap,
48 );
49
50 const shouldUseWebpackImporter =
51 typeof options.webpackImporter === "boolean"
52 ? options.webpackImporter
53 : true;
54
55 if (shouldUseWebpackImporter) {
56 sassOptions.importers.push(getModernWebpackImporter(this));
57 }
58
59 let compile;
60
61 try {
62 compile = getCompileFn(this, implementation, options.api);
63 } catch (error) {
64 callback(/** @type {Error} */ (error));
65 return;
66 }
67
68 let result;
69
70 try {
71 result = await compile(sassOptions);
72 } catch (error) {
73 const sassError = /** @type {SassError} */ (error);
74
75 // There are situations when the `span.url` property does not exist
76 if (sassError.span && typeof sassError.span.url !== "undefined") {
77 this.addDependency(url.fileURLToPath(sassError.span.url));
78 }
79
80 callback(errorFactory(sassError));
81
82 return;

Callers

nothing calls this directly

Calls 6

getSassImplementationFunction · 0.90
getSassOptionsFunction · 0.90
getModernWebpackImporterFunction · 0.90
getCompileFnFunction · 0.90
errorFactoryFunction · 0.90
normalizeSourceMapFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…