-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlasso-minify-css-plugin.js
48 lines (36 loc) · 1.18 KB
/
lasso-minify-css-plugin.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
var sqwish = require('sqwish');
function minify(src, options) {
if (!options) {
options = {};
}
//var strict = options.mergeDuplicates !== false;
return sqwish.minify(src, false);
}
function isInline(lassoContext) {
if (lassoContext.inline === true) {
return true;
}
if (lassoContext.dependency && lassoContext.dependency.inline === true) {
return true;
}
return false;
}
module.exports = function (lasso, pluginConfig) {
lasso.addTransform({
contentType: 'css',
name: module.id,
stream: false,
transform: function(code, lassoContext) {
if (pluginConfig.inlineOnly === true && !isInline(lassoContext)) {
// Skip minification when we are not minifying inline code
return code;
}
var dependency = lassoContext.dependency;
var mergeDuplicates = dependency ? dependency.mergeDuplicates !== false : true;
var minified = minify(code, {
mergeDuplicates: mergeDuplicates
});
return minified;
}
});
};