source: frontend/node_modules/sass-loader/dist/index.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.4 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _url = _interopRequireDefault(require("url"));
9
10var _path = _interopRequireDefault(require("path"));
11
12var _options = _interopRequireDefault(require("./options.json"));
13
14var _utils = require("./utils");
15
16var _SassError = _interopRequireDefault(require("./SassError"));
17
18function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
20/**
21 * The sass-loader makes node-sass and dart-sass available to webpack modules.
22 *
23 * @this {object}
24 * @param {string} content
25 */
26async function loader(content) {
27 const options = this.getOptions(_options.default);
28 const callback = this.async();
29 const implementation = (0, _utils.getSassImplementation)(this, options.implementation);
30
31 if (!implementation) {
32 callback();
33 return;
34 }
35
36 const useSourceMap = typeof options.sourceMap === "boolean" ? options.sourceMap : this.sourceMap;
37 const sassOptions = await (0, _utils.getSassOptions)(this, options, content, implementation, useSourceMap);
38 const shouldUseWebpackImporter = typeof options.webpackImporter === "boolean" ? options.webpackImporter : true;
39
40 if (shouldUseWebpackImporter) {
41 const isModernAPI = options.api === "modern";
42
43 if (!isModernAPI) {
44 const {
45 includePaths
46 } = sassOptions;
47 sassOptions.importer.push((0, _utils.getWebpackImporter)(this, implementation, includePaths));
48 } else {
49 sassOptions.importers.push((0, _utils.getModernWebpackImporter)(this, implementation));
50 }
51 }
52
53 const compile = (0, _utils.getCompileFn)(implementation, options);
54 let result;
55
56 try {
57 result = await compile(sassOptions, options);
58 } catch (error) {
59 // There are situations when the `file`/`span.url` property do not exist
60 // Modern API
61 if (error.span && typeof error.span.url !== "undefined") {
62 this.addDependency(_url.default.fileURLToPath(error.span.url));
63 } // Legacy API
64 else if (typeof error.file !== "undefined") {
65 // `node-sass` returns POSIX paths
66 this.addDependency(_path.default.normalize(error.file));
67 }
68
69 callback(new _SassError.default(error));
70 return;
71 }
72
73 let map = // Modern API, then legacy API
74 result.sourceMap ? result.sourceMap : result.map ? JSON.parse(result.map) : null; // Modify source paths only for webpack, otherwise we do nothing
75
76 if (map && useSourceMap) {
77 map = (0, _utils.normalizeSourceMap)(map, this.rootContext);
78 } // Modern API
79
80
81 if (typeof result.loadedUrls !== "undefined") {
82 result.loadedUrls.forEach(includedFile => {
83 const normalizedIncludedFile = _url.default.fileURLToPath(includedFile); // Custom `importer` can return only `contents` so includedFile will be relative
84
85
86 if (_path.default.isAbsolute(normalizedIncludedFile)) {
87 this.addDependency(normalizedIncludedFile);
88 }
89 });
90 } // Legacy API
91 else if (typeof result.stats !== "undefined" && typeof result.stats.includedFiles !== "undefined") {
92 result.stats.includedFiles.forEach(includedFile => {
93 const normalizedIncludedFile = _path.default.normalize(includedFile); // Custom `importer` can return only `contents` so includedFile will be relative
94
95
96 if (_path.default.isAbsolute(normalizedIncludedFile)) {
97 this.addDependency(normalizedIncludedFile);
98 }
99 });
100 }
101
102 callback(null, result.css.toString(), map);
103}
104
105var _default = loader;
106exports.default = _default;
Note: See TracBrowser for help on using the repository browser.