@lipemat/js-boilerplate
Version:
Dependencies and scripts for a no config JavaScript app
46 lines (45 loc) • 1.65 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.postcss = void 0;
/**
* Mimic the `postcss-clean` plugin.
*
* Override due to the plugin using version 4 of `clean-css`, which
* has issues with PostCSS 7/8 and results in inconsistent CSS.
*
* This may potentially be removed in favor of using that plugin again if
* they change the version of PostCSS to 8 and Clean CSS to 5.
*
* Decided to use this `lib` instead of maintaining another fork.
*
* @link https://www.npmjs.com/package/postcss-clean
*
*/
const postcss_1 = __importDefault(require("postcss"));
// Can't use `import` due to the plugin not supporting a default export.
const CleanCSS = require('clean-css');
const cleaner = (opts = {}) => {
const clean = new CleanCSS(opts);
return {
postcssPlugin: 'clean',
OnceExit(css, { result }) {
return new Promise((resolve, reject) => {
clean.minify(css.toString(), (err, min) => {
if (null !== err) {
return reject(new Error(err.join('\n')));
}
if (min.warnings.length > 0) {
return reject(new Error('postcss-clean minify failed! \n' + min.warnings.join('\n')));
}
result.root = postcss_1.default.parse(min.styles);
resolve();
});
});
},
};
};
exports.postcss = true;
exports.default = cleaner;