Please Notice - this package is a fork of rollup-plugin-terser.
most of this code was not written by us, it was only slightly modified in order to support providing the API with generated sourcemaps
Rollup plugin to minify generated es bundle. Uses terser under the hood.
yarn add rollup-plugin-terser --devNote: this package requires [email protected] and higher (including [email protected])
import { rollup } from "rollup";
import { terser } from "rollup-plugin-terser";
rollup({
input: "main.js",
plugins: [terser()]
});- Module is a namespace. Default export often leads to function/component per file dogma and makes code less maintainable.
- Interop with commonjs is broken in many cases. A ways to fight them are known.
- Show me any good language with default exports. It's historical javascriptism.
⚠️ Caveat: any function used in options object cannot rely on its surrounding scope, since it is executed in an isolated context.
terser(options);options - terser API options
options.sourcemap: boolean
Generates source maps and passes them to rollup. Defaults to true.
options.numWorkers: number
Amount of workers to spawn. Defaults to the number of CPUs minus 1.
If you'd like to preserve comments (for licensing for example), then you can specify a function to do this like so:
terser({
output: {
comments: function(node, comment) {
var text = comment.value;
var type = comment.type;
if (type == "comment2") {
// multiline comment
return /@preserve|@license|@cc_on/i.test(text);
}
}
}
});Alternatively, you can also choose to keep all comments (e.g. if a licensing header has already been prepended by a previous rollup plugin):
terser({
output: {
comments: "all"
}
});See Terser documentation for further reference.
MIT © Bogdan Chadkin