-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
49 lines (39 loc) · 1.39 KB
/
index.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
var utils = require('loader-utils');
var compass = require('compass-node');
var path = require('path');
module.exports = function (content) {
this.cacheable();
var callback = this.async();
var opt = utils.parseQuery(this.query);
opt.data = content;
// skip empty files, otherwise it will stop webpack, see issue #21
if (opt.data.trim() === '') {
return callback(null, content);
}
// set include path to fix imports
opt.includePaths = opt.includePaths || [];
opt.includePaths.push(path.dirname(this.resourcePath));
if (this.options.resolve && this.options.resolve.root) {
var root = [].concat(this.options.resolve.root);
opt.includePaths = opt.includePaths.concat(root);
}
opt.spriteDist = opt.spriteOutput || '';
// output compressed by default
opt.outputStyle = opt.outputStyle || 'compressed';
opt.stats = {};
var loadPaths = opt.includePaths;
var markDependencies = function (deps) {
deps.forEach(function(file) {
this.addDependency(file);
}.bind(this))
}.bind(this);
opt.success = function (css) {
markDependencies( (css.stats && css.stats.includedFiles || []) )
callback(null, css.css);
}.bind(this);
opt.error = function (err) {
this.emitError(err);
callback(err);
}.bind(this);
compass.render(this.resourcePath, opt);
};