-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
SASSAsset.js
45 lines (39 loc) · 1.34 KB
/
SASSAsset.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
const CSSAsset = require('./CSSAsset');
const config = require('../utils/config');
const localRequire = require('../utils/localRequire');
const promisify = require('../utils/promisify');
const path = require('path');
class SASSAsset extends CSSAsset {
async parse(code) {
// node-sass should be installed locally in the module that's being required
let sass = localRequire('node-sass', this.name);
let render = promisify(sass.render.bind(sass));
let opts =
this.package.sass ||
(await config.load(this.name, ['.sassrc', '.sassrc.js'])) ||
{};
opts.includePaths = (opts.includePaths || []).concat(
path.dirname(this.name)
);
opts.data = code;
opts.indentedSyntax =
typeof opts.indentedSyntax === 'boolean'
? opts.indentedSyntax
: path.extname(this.name).toLowerCase() === '.sass';
opts.functions = Object.assign({}, opts.functions, {
url: node => {
let filename = this.addURLDependency(node.getValue());
return new sass.types.String(`url(${JSON.stringify(filename)})`);
}
});
let res = await render(opts);
res.render = () => res.css.toString();
return res;
}
collectDependencies() {
for (let dep of this.ast.stats.includedFiles) {
this.addDependency(dep, {includedInParent: true});
}
}
}
module.exports = SASSAsset;