[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | exports.default = void 0;
|
---|
| 7 |
|
---|
| 8 | var _path = _interopRequireDefault(require("path"));
|
---|
| 9 |
|
---|
| 10 | var _options = _interopRequireDefault(require("./options.json"));
|
---|
| 11 |
|
---|
| 12 | var _utils = require("./utils");
|
---|
| 13 |
|
---|
| 14 | var _SassError = _interopRequireDefault(require("./SassError"));
|
---|
| 15 |
|
---|
| 16 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
| 17 |
|
---|
| 18 | /**
|
---|
| 19 | * The sass-loader makes node-sass and dart-sass available to webpack modules.
|
---|
| 20 | *
|
---|
| 21 | * @this {object}
|
---|
| 22 | * @param {string} content
|
---|
| 23 | */
|
---|
| 24 | async function loader(content) {
|
---|
| 25 | const options = this.getOptions(_options.default);
|
---|
| 26 | const callback = this.async();
|
---|
| 27 | const implementation = (0, _utils.getSassImplementation)(this, options.implementation);
|
---|
| 28 |
|
---|
| 29 | if (!implementation) {
|
---|
| 30 | callback();
|
---|
| 31 | return;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | const useSourceMap = typeof options.sourceMap === "boolean" ? options.sourceMap : this.sourceMap;
|
---|
| 35 | const sassOptions = await (0, _utils.getSassOptions)(this, options, content, implementation, useSourceMap);
|
---|
| 36 | const shouldUseWebpackImporter = typeof options.webpackImporter === "boolean" ? options.webpackImporter : true;
|
---|
| 37 |
|
---|
| 38 | if (shouldUseWebpackImporter) {
|
---|
| 39 | const {
|
---|
| 40 | includePaths
|
---|
| 41 | } = sassOptions;
|
---|
| 42 | sassOptions.importer.push((0, _utils.getWebpackImporter)(this, implementation, includePaths));
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | const render = (0, _utils.getRenderFunctionFromSassImplementation)(implementation);
|
---|
| 46 | render(sassOptions, (error, result) => {
|
---|
| 47 | if (error) {
|
---|
| 48 | // There are situations when the `file` property do not exist
|
---|
| 49 | if (error.file) {
|
---|
| 50 | // `node-sass` returns POSIX paths
|
---|
| 51 | this.addDependency(_path.default.normalize(error.file));
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | callback(new _SassError.default(error));
|
---|
| 55 | return;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | let map = result.map ? JSON.parse(result.map) : null; // Modify source paths only for webpack, otherwise we do nothing
|
---|
| 59 |
|
---|
| 60 | if (map && useSourceMap) {
|
---|
| 61 | map = (0, _utils.normalizeSourceMap)(map, this.rootContext);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | result.stats.includedFiles.forEach(includedFile => {
|
---|
| 65 | const normalizedIncludedFile = _path.default.normalize(includedFile); // Custom `importer` can return only `contents` so includedFile will be relative
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | if (_path.default.isAbsolute(normalizedIncludedFile)) {
|
---|
| 69 | this.addDependency(normalizedIncludedFile);
|
---|
| 70 | }
|
---|
| 71 | });
|
---|
| 72 | callback(null, result.css.toString(), map);
|
---|
| 73 | });
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | var _default = loader;
|
---|
| 77 | exports.default = _default; |
---|