Repository navigation
Expand file tree
/
Copy pathclean-css-processor.js
More file actions
64 lines (52 loc) · 2.01 KB
/
Copy pathclean-css-processor.js
File metadata and controls
64 lines (52 loc) · 2.01 KB
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
62
63
64
"use strict";
const CleanCSS = require("clean-css");
module.exports = function () {
function CleanCSSProcessor(options) {
this.options = options || {};
}
CleanCSSProcessor.prototype = {
process: function (css, extra) {
let options = this.options,
sourceMap = extra.sourceMap,
sources,
sourcesContent;
if (sourceMap) {
options.sourceMap = sourceMap.getExternalSourceMap();
if (options.sourceMap) {
options.sourceMap = options.sourceMap.toString();
const sourceMapObj = JSON.parse(options.sourceMap);
if (sourceMapObj.sourcesContent) {
sourcesContent = sourceMapObj.sourcesContent;
sources = sourceMapObj.sources;
}
}
}
if (typeof options.keepSpecialComments === "undefined") {
options.keepSpecialComments = "*";
}
options.processImport = false;
if (typeof options.rebase === "undefined") {
options.rebase = false;
}
if (typeof options.advanced === "undefined") {
options.advanced = false;
}
const output = new CleanCSS(options).minify(css);
if (sourceMap) {
if (sourcesContent) {
for (let source = 0; source < sources.length; source++) {
output.sourceMap.setSourceContent(sources[source], sourcesContent[source]);
}
}
sourceMap.setExternalSourceMap(JSON.stringify(output.sourceMap));
}
let outputCSS = output.styles;
if (sourceMap) {
const sourceMapURL = sourceMap.getSourceMapURL();
outputCSS += sourceMap.getCSSAppendage();
}
return outputCSS;
}
};
return CleanCSSProcessor;
};