sass-loader 8.0.2 → 9.0.3
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/CHANGELOG.md +46 -0
- package/README.md +83 -57
- package/dist/SassError.js +2 -3
- package/dist/index.js +19 -50
- package/dist/options.json +2 -2
- package/dist/utils.js +383 -0
- package/package.json +35 -38
- package/dist/getDefaultSassImplementation.js +0 -28
- package/dist/getRenderFunctionFromSassImplementation.js +0 -39
- package/dist/getSassImplementation.js +0 -56
- package/dist/getSassOptions.js +0 -116
- package/dist/importsToResolve.js +0 -88
- package/dist/proxyCustomImporters.js +0 -31
- package/dist/webpackImporter.js +0 -75
package/dist/getSassOptions.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _os = _interopRequireDefault(require("os"));
|
|
9
|
-
|
|
10
|
-
var _path = _interopRequireDefault(require("path"));
|
|
11
|
-
|
|
12
|
-
var _cloneDeep = _interopRequireDefault(require("clone-deep"));
|
|
13
|
-
|
|
14
|
-
var _proxyCustomImporters = _interopRequireDefault(require("./proxyCustomImporters"));
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
function isProductionLikeMode(loaderContext) {
|
|
19
|
-
return loaderContext.mode === 'production' || !loaderContext.mode || loaderContext.minimize;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Derives the sass options from the loader context and normalizes its values with sane defaults.
|
|
23
|
-
*
|
|
24
|
-
* @param {object} loaderContext
|
|
25
|
-
* @param {object} loaderOptions
|
|
26
|
-
* @param {string} content
|
|
27
|
-
* @param {object} implementation
|
|
28
|
-
* @returns {Object}
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
function getSassOptions(loaderContext, loaderOptions, content, implementation) {
|
|
33
|
-
const options = (0, _cloneDeep.default)(loaderOptions.sassOptions ? typeof loaderOptions.sassOptions === 'function' ? loaderOptions.sassOptions(loaderContext) || {} : loaderOptions.sassOptions : {});
|
|
34
|
-
const isDartSass = implementation.info.includes('dart-sass');
|
|
35
|
-
|
|
36
|
-
if (isDartSass) {
|
|
37
|
-
const shouldTryToResolveFibers = !options.fiber && options.fiber !== false;
|
|
38
|
-
|
|
39
|
-
if (shouldTryToResolveFibers) {
|
|
40
|
-
let fibers;
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
fibers = require.resolve('fibers');
|
|
44
|
-
} catch (_error) {// Nothing
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (fibers) {
|
|
48
|
-
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
49
|
-
options.fiber = require(fibers);
|
|
50
|
-
}
|
|
51
|
-
} else if (options.fiber === false) {
|
|
52
|
-
// Don't pass the `fiber` option for `sass` (`Dart Sass`)
|
|
53
|
-
delete options.fiber;
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
// Don't pass the `fiber` option for `node-sass`
|
|
57
|
-
delete options.fiber;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
options.data = loaderOptions.prependData ? typeof loaderOptions.prependData === 'function' ? loaderOptions.prependData(loaderContext) + _os.default.EOL + content : loaderOptions.prependData + _os.default.EOL + content : content; // opt.outputStyle
|
|
61
|
-
|
|
62
|
-
if (!options.outputStyle && isProductionLikeMode(loaderContext)) {
|
|
63
|
-
options.outputStyle = 'compressed';
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const useSourceMap = typeof loaderOptions.sourceMap === 'boolean' ? loaderOptions.sourceMap : loaderContext.sourceMap; // opt.sourceMap
|
|
67
|
-
// Not using the `this.sourceMap` flag because css source maps are different
|
|
68
|
-
// @see https://github.com/webpack/css-loader/pull/40
|
|
69
|
-
|
|
70
|
-
if (useSourceMap) {
|
|
71
|
-
// Deliberately overriding the sourceMap option here.
|
|
72
|
-
// node-sass won't produce source maps if the data option is used and options.sourceMap is not a string.
|
|
73
|
-
// In case it is a string, options.sourceMap should be a path where the source map is written.
|
|
74
|
-
// But since we're using the data option, the source map will not actually be written, but
|
|
75
|
-
// all paths in sourceMap.sources will be relative to that path.
|
|
76
|
-
// Pretty complicated... :(
|
|
77
|
-
options.sourceMap = _path.default.join(process.cwd(), '/sass.map');
|
|
78
|
-
|
|
79
|
-
if ('sourceMapRoot' in options === false) {
|
|
80
|
-
options.sourceMapRoot = process.cwd();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if ('omitSourceMapUrl' in options === false) {
|
|
84
|
-
// The source map url doesn't make sense because we don't know the output path
|
|
85
|
-
// The css-loader will handle that for us
|
|
86
|
-
options.omitSourceMapUrl = true;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if ('sourceMapContents' in options === false) {
|
|
90
|
-
// If sourceMapContents option is not set, set it to true otherwise maps will be empty/null
|
|
91
|
-
// when exported by webpack-extract-text-plugin.
|
|
92
|
-
options.sourceMapContents = true;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const {
|
|
97
|
-
resourcePath
|
|
98
|
-
} = loaderContext;
|
|
99
|
-
|
|
100
|
-
const ext = _path.default.extname(resourcePath); // If we are compiling sass and indentedSyntax isn't set, automatically set it.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (ext && ext.toLowerCase() === '.sass' && 'indentedSyntax' in options === false) {
|
|
104
|
-
options.indentedSyntax = true;
|
|
105
|
-
} else {
|
|
106
|
-
options.indentedSyntax = Boolean(options.indentedSyntax);
|
|
107
|
-
} // Allow passing custom importers to `node-sass`. Accepts `Function` or an array of `Function`s.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
options.importer = options.importer ? (0, _proxyCustomImporters.default)(options.importer, resourcePath) : [];
|
|
111
|
-
options.includePaths = (options.includePaths || []).concat(_path.default.dirname(resourcePath));
|
|
112
|
-
return options;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
var _default = getSassOptions;
|
|
116
|
-
exports.default = _default;
|
package/dist/importsToResolve.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
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 _loaderUtils = _interopRequireDefault(require("loader-utils"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
// Examples:
|
|
15
|
-
// - ~package
|
|
16
|
-
// - ~package/
|
|
17
|
-
// - ~@org
|
|
18
|
-
// - ~@org/
|
|
19
|
-
// - ~@org/package
|
|
20
|
-
// - ~@org/package/
|
|
21
|
-
const matchModuleImport = /^~([^/]+|[^/]+\/|@[^/]+[/][^/]+|@[^/]+\/?|@[^/]+[/][^/]+\/)$/;
|
|
22
|
-
/**
|
|
23
|
-
* When libsass tries to resolve an import, it uses a special algorithm.
|
|
24
|
-
* Since the sass-loader uses webpack to resolve the modules, we need to simulate that algorithm. This function
|
|
25
|
-
* returns an array of import paths to try. The last entry in the array is always the original url
|
|
26
|
-
* to enable straight-forward webpack.config aliases.
|
|
27
|
-
*
|
|
28
|
-
* @param {string} url
|
|
29
|
-
* @returns {Array<string>}
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
function importsToResolve(url) {
|
|
33
|
-
const request = _loaderUtils.default.urlToRequest(url); // Keep in mind: ext can also be something like '.datepicker' when the true extension is omitted and the filename contains a dot.
|
|
34
|
-
// @see https://github.com/webpack-contrib/sass-loader/issues/167
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const ext = _path.default.extname(request).toLowerCase(); // In case there is module request, send this to webpack resolver
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (matchModuleImport.test(url)) {
|
|
41
|
-
return [request, url];
|
|
42
|
-
} // Because @import is also defined in CSS, Sass needs a way of compiling plain CSS @imports without trying to import the files at compile time.
|
|
43
|
-
// To accomplish this, and to ensure SCSS is as much of a superset of CSS as possible, Sass will compile any @imports with the following characteristics to plain CSS imports:
|
|
44
|
-
// - imports where the URL ends with .css.
|
|
45
|
-
// - imports where the URL begins http:// or https://.
|
|
46
|
-
// - imports where the URL is written as a url().
|
|
47
|
-
// - imports that have media queries.
|
|
48
|
-
//
|
|
49
|
-
// The `node-sass` package sends `@import` ending on `.css` to importer, it is bug, so we skip resolve
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (ext === '.css') {
|
|
53
|
-
return [];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const dirname = _path.default.dirname(request);
|
|
57
|
-
|
|
58
|
-
const basename = _path.default.basename(request); // In case there is file extension:
|
|
59
|
-
//
|
|
60
|
-
// 1. Try to resolve `_` file.
|
|
61
|
-
// 2. Try to resolve file without `_`.
|
|
62
|
-
// 3. Send a original url to webpack resolver, maybe it is alias.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (['.scss', '.sass'].includes(ext)) {
|
|
66
|
-
return [`${dirname}/_${basename}`, `${dirname}/${basename}`, url];
|
|
67
|
-
} // In case there is no file extension and filename starts with `_`:
|
|
68
|
-
//
|
|
69
|
-
// 1. Try to resolve files with `scss`, `sass` and `css` extensions.
|
|
70
|
-
// 2. Try to resolve directory with `_index` or `index` filename.
|
|
71
|
-
// 3. Send the original url to webpack resolver, maybe it's alias.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (basename.startsWith('_')) {
|
|
75
|
-
return [`${request}.scss`, `${request}.sass`, `${request}.css`, request, url];
|
|
76
|
-
} // In case there is no file extension and filename doesn't start with `_`:
|
|
77
|
-
//
|
|
78
|
-
// 1. Try to resolve file starts with `_` and with extensions
|
|
79
|
-
// 2. Try to resolve file with extensions
|
|
80
|
-
// 3. Try to resolve directory with `_index` or `index` filename.
|
|
81
|
-
// 4. Send a original url to webpack resolver, maybe it is alias.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return [`${dirname}/_${basename}.scss`, `${dirname}/_${basename}.sass`, `${dirname}/_${basename}.css`, `${request}.scss`, `${request}.sass`, `${request}.css`, request, url];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
var _default = importsToResolve;
|
|
88
|
-
exports.default = _default;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Creates new custom importers that use the given `resourcePath` if libsass calls the custom importer with `prev`
|
|
10
|
-
* being 'stdin'.
|
|
11
|
-
*
|
|
12
|
-
* Why do we need this? We have to use the `data` option of node-sass in order to compile our sass because
|
|
13
|
-
* the `resourcePath` might not be an actual file on disk. When using the `data` option, libsass uses the string
|
|
14
|
-
* 'stdin' instead of a filename.
|
|
15
|
-
*
|
|
16
|
-
* We have to fix this behavior in order to provide a consistent experience to the webpack user.
|
|
17
|
-
*
|
|
18
|
-
* @param {Function|Array<Function>} importer
|
|
19
|
-
* @param {string} resourcePath
|
|
20
|
-
* @returns {Array<Function>}
|
|
21
|
-
*/
|
|
22
|
-
function proxyCustomImporters(importer, resourcePath) {
|
|
23
|
-
return [].concat(importer).map( // eslint-disable-next-line no-shadow
|
|
24
|
-
importer => function customImporter() {
|
|
25
|
-
return importer.apply(this, // eslint-disable-next-line prefer-rest-params
|
|
26
|
-
Array.from(arguments).map((arg, i) => i === 1 && arg === 'stdin' ? resourcePath : arg));
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
var _default = proxyCustomImporters;
|
|
31
|
-
exports.default = _default;
|
package/dist/webpackImporter.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
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 _importsToResolve = _interopRequireDefault(require("./importsToResolve"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @name PromisedResolve
|
|
16
|
-
* @type {Function}
|
|
17
|
-
* @param {string} dir
|
|
18
|
-
* @param {string} request
|
|
19
|
-
* @returns Promise
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @name Importer
|
|
24
|
-
* @type {Function}
|
|
25
|
-
* @param {string} url
|
|
26
|
-
* @param {string} prev
|
|
27
|
-
* @param {Function<Error, string>} done
|
|
28
|
-
*/
|
|
29
|
-
const matchCss = /\.css$/i;
|
|
30
|
-
/**
|
|
31
|
-
* Returns an importer that uses webpack's resolving algorithm.
|
|
32
|
-
*
|
|
33
|
-
* It's important that the returned function has the correct number of arguments
|
|
34
|
-
* (based on whether the call is sync or async) because otherwise node-sass doesn't exit.
|
|
35
|
-
*
|
|
36
|
-
* @param {string} resourcePath
|
|
37
|
-
* @param {PromisedResolve} resolve
|
|
38
|
-
* @param {Function<string>} addNormalizedDependency
|
|
39
|
-
* @returns {Importer}
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
function webpackImporter(resourcePath, resolve, addNormalizedDependency) {
|
|
43
|
-
function dirContextFrom(fileContext) {
|
|
44
|
-
return _path.default.dirname( // The first file is 'stdin' when we're using the data option
|
|
45
|
-
fileContext === 'stdin' ? resourcePath : fileContext);
|
|
46
|
-
} // eslint-disable-next-line no-shadow
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
function startResolving(dir, importsToResolve) {
|
|
50
|
-
return importsToResolve.length === 0 ? Promise.reject() : resolve(dir, importsToResolve[0]).then(resolvedFile => {
|
|
51
|
-
// Add the resolvedFilename as dependency. Although we're also using stats.includedFiles, this might come
|
|
52
|
-
// in handy when an error occurs. In this case, we don't get stats.includedFiles from node-sass.
|
|
53
|
-
addNormalizedDependency(resolvedFile);
|
|
54
|
-
return {
|
|
55
|
-
// By removing the CSS file extension, we trigger node-sass to include the CSS file instead of just linking it.
|
|
56
|
-
file: resolvedFile.replace(matchCss, '')
|
|
57
|
-
};
|
|
58
|
-
}, () => {
|
|
59
|
-
const [, ...tailResult] = importsToResolve;
|
|
60
|
-
return startResolving(dir, tailResult);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return (url, prev, done) => {
|
|
65
|
-
startResolving(dirContextFrom(prev), (0, _importsToResolve.default)(url)) // Catch all resolving errors, return the original file and pass responsibility back to other custom importers
|
|
66
|
-
.catch(() => {
|
|
67
|
-
return {
|
|
68
|
-
file: url
|
|
69
|
-
};
|
|
70
|
-
}).then(done);
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
var _default = webpackImporter;
|
|
75
|
-
exports.default = _default;
|