You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.2 KiB
37 lines
1.2 KiB
"use strict";
|
|
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const cssnano = require("cssnano");
|
|
|
|
module.exports = (params, processor) => ({
|
|
"process": () => {
|
|
const filePath = path.join(processor.context.exported, params.filename);
|
|
|
|
fs.readFile(filePath, (readErr, css) => {
|
|
if (readErr) {
|
|
processor.onError(`Unable to read stylesheet ${params.filename}: ${readErr}`);
|
|
|
|
return processor.done();
|
|
}
|
|
|
|
return cssnano.process(css)
|
|
.catch((cssErr) => {
|
|
processor.onError(`Unable to uglify stylesheet: ${cssErr}`);
|
|
processor.done();
|
|
})
|
|
.then((result) => {
|
|
fs.writeFile(filePath, result.css, (writeErr) => {
|
|
if (writeErr) {
|
|
processor.onError(`Unable to write uglified stylesheet for ${params.filename}: ${writeErr}`);
|
|
} else {
|
|
processor.onInfo(`Saved uglified stylesheet for ${params.filename}; uglified length: ${result.css.length}`);
|
|
}
|
|
|
|
processor.done();
|
|
});
|
|
});
|
|
});
|
|
}
|
|
});
|
|
|
|
|