yarn add rollup-plugin-terser --dev
Note: this package requires firstname.lastname@example.org and higher (including email@example.com)
Why named export?
- 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 or hard to maintain.
⚠️ Caveat: any function used in options object cannot rely on its surrounding scope, since it is executed in an isolated context.
options - terser API options
Note: some terser options are set by the plugin automatically:
module: trueis set when
toplevel: trueis set when
Generates source maps and passes them to rollup. Defaults to
Amount of workers to spawn. Defaults to the number of CPUs minus 1.
options.include: Array<string | RegExp> | string | RegExp
options.exclude: Array<string | RegExp> | string | RegExp
Specifically include/exclude chunk files names (minimatch pattern, or array of minimatch patterns), By default all chunk files will be minify.
Using as output plugin
// rollup.config.js;input: "index.js"output:file: "lib.js" format: "cjs"file: "lib.min.js" format: "cjs" plugins:file: "lib.esm.js" format: "esm";
If you'd like that only some of the files will be minify, then you can filter by
exclude to do this like so:
// rollup.config.js;input: "index.js"output:file: "lib.js" format: "cjs"file: "lib.min.js" format: "cjs"file: "lib.esm.js" format: "esm"dir: "." entryFileNames: "lib-[format].js" format: "iife"plugins:;
If you'd like to preserve comments (for licensing for example), then you can specify a function to do this like so:
Alternatively, you can also choose to keep all comments (e.g. if a licensing header has already been prepended by a previous rollup plugin):
See Terser documentation for further reference.
MIT © Bogdan Chadkin