-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminify.js
More file actions
43 lines (37 loc) · 1.34 KB
/
Copy pathminify.js
File metadata and controls
43 lines (37 loc) · 1.34 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
'use strict';
const Filter = require('broccoli-persistent-filter');
const CleanCSS = require('clean-css');
const { transform } = require('lightningcss');
function LightningCssFilter(inputTree) {
Filter.call(this, inputTree, {
extensions: ['css'],
targetExtension: 'css',
persist: true,
});
}
LightningCssFilter.prototype = Object.create(Filter.prototype);
LightningCssFilter.prototype.constructor = LightningCssFilter;
LightningCssFilter.prototype.baseDir = function () {
return __dirname;
};
LightningCssFilter.prototype.processString = function (css, relativePath) {
// Some older Ember applications emit legacy nested at-rules in app CSS
// that CleanCSS accepts. Modern third-party vendor CSS may use native CSS
// nesting that CleanCSS 3 cannot parse, so minify each bundle accordingly.
if (!relativePath.endsWith('vendor.css')) {
const result = new CleanCSS().minify(css);
if (result.errors.length) {
throw new Error(result.errors.join('\n'));
}
return result.styles;
}
return transform({
filename: relativePath,
code: Buffer.from(css),
minify: true,
}).code.toString();
};
module.exports = function minifyWithLightningCss(tree) {
return new LightningCssFilter(tree);
};
module.exports.LightningCssFilter = LightningCssFilter;