rollup-plugin-html-literals
Version:
A Rollup plugin to minify html template literals
32 lines (28 loc) • 824 B
JavaScript
;
var minifyLiterals = require('minify-literals');
var pluginutils = require('@rollup/pluginutils');
var index = (options = {}) => {
if (!options.minifyHTMLLiterals) {
options.minifyHTMLLiterals = minifyLiterals.minifyHTMLLiterals;
}
if (!options.filter) {
options.filter = pluginutils.createFilter(options.include, options.exclude);
}
const minifyOptions = options.options || {};
return {
name: "html-literals",
transform(code, id) {
if (!options.filter(id)) return null;
try {
return options.minifyHTMLLiterals(code, { ...minifyOptions, fileName: id });
} catch (error) {
if (options.failOnError) {
this.error(error.message);
} else {
this.warn(error.message);
}
}
}
};
};
module.exports = index;