forked from symfony/webpack-encore
/
sass.js
55 lines (48 loc) · 1.91 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
/*
* 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';
const WebpackConfig = require('../WebpackConfig'); //eslint-disable-line no-unused-vars
const loaderFeatures = require('../features');
const cssLoader = require('./css');
const applyOptionsCallback = require('../utils/apply-options-callback');
module.exports = {
/**
* @param {WebpackConfig} webpackConfig
* @param {boolean} useCssModules
* @return {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: 'resolve-url-loader',
options: Object.assign(
{
sourceMap: webpackConfig.useSourceMaps,
outputStyle: 'nested'
},
webpackConfig.sassOptions.resolveUrlLoaderOptions
)
});
}
const config = Object.assign({}, {
// needed by the resolve-url-loader
sourceMap: (true === webpackConfig.sassOptions.resolveUrlLoader) || webpackConfig.useSourceMaps
});
sassLoaders.push({
loader: 'sass-loader',
options: applyOptionsCallback(webpackConfig.sassLoaderOptionsCallback, config)
});
return sassLoaders;
}
};