-
-
Notifications
You must be signed in to change notification settings - Fork 198
/
Copy pathsass.js
61 lines (53 loc) · 2.02 KB
/
sass.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* This file is part of the Symfony Webpack Encore package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
'use strict';
/**
* @import WebpackConfig from '../WebpackConfig'
*/
const loaderFeatures = require('../features');
const cssLoader = require('./css');
const applyOptionsCallback = require('../utils/apply-options-callback');
module.exports = {
/**
* @param {WebpackConfig} webpackConfig
* @param {boolean} useCssModules
* @returns {Array} of loaders to use for Sass files
*/
getLoaders(webpackConfig, useCssModules = false) {
loaderFeatures.ensurePackagesExistAndAreCorrectVersion('sass');
const sassLoaders = [...cssLoader.getLoaders(webpackConfig, useCssModules)];
if (true === webpackConfig.sassOptions.resolveUrlLoader) {
// responsible for resolving Sass url() paths
// without this, all url() paths must be relative to the
// entry file, not the file that contains the url()
sassLoaders.push({
loader: require.resolve('resolve-url-loader'),
options: Object.assign(
{
sourceMap: webpackConfig.useSourceMaps
},
webpackConfig.sassOptions.resolveUrlLoaderOptions
)
});
}
const config = Object.assign({}, {
// needed by the resolve-url-loader
sourceMap: (true === webpackConfig.sassOptions.resolveUrlLoader) || webpackConfig.useSourceMaps,
sassOptions: {
// CSS minification is handled with mini-css-extract-plugin
outputStyle: 'expanded'
}
});
sassLoaders.push({
loader: require.resolve('sass-loader'),
options: applyOptionsCallback(webpackConfig.sassLoaderOptionsCallback, config)
});
return sassLoaders;
}
};