1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var _url = _interopRequireDefault(require("url"));
|
9 |
|
10 | var _path = _interopRequireDefault(require("path"));
|
11 |
|
12 | var _options = _interopRequireDefault(require("./options.json"));
|
13 |
|
14 | var _utils = require("./utils");
|
15 |
|
16 | var _SassError = _interopRequireDefault(require("./SassError"));
|
17 |
|
18 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | async 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 |
|
60 |
|
61 | if (error.span && typeof error.span.url !== "undefined") {
|
62 | this.addDependency(_url.default.fileURLToPath(error.span.url));
|
63 | }
|
64 | else if (typeof error.file !== "undefined") {
|
65 |
|
66 | this.addDependency(_path.default.normalize(error.file));
|
67 | }
|
68 |
|
69 | callback(new _SassError.default(error));
|
70 | return;
|
71 | }
|
72 |
|
73 | let map =
|
74 | result.sourceMap ? result.sourceMap : result.map ? JSON.parse(result.map) : null;
|
75 |
|
76 | if (map && useSourceMap) {
|
77 | map = (0, _utils.normalizeSourceMap)(map, this.rootContext);
|
78 | }
|
79 |
|
80 |
|
81 | if (typeof result.loadedUrls !== "undefined") {
|
82 | result.loadedUrls.forEach(includedFile => {
|
83 | const normalizedIncludedFile = _url.default.fileURLToPath(includedFile);
|
84 |
|
85 |
|
86 | if (_path.default.isAbsolute(normalizedIncludedFile)) {
|
87 | this.addDependency(normalizedIncludedFile);
|
88 | }
|
89 | });
|
90 | }
|
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);
|
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 |
|
105 | var _default = loader;
|
106 | exports.default = _default; |
\ | No newline at end of file |