7.0.2 • Published 4 years ago

rollup-plugin-terser v7.0.2

Weekly downloads
1,713,495
License
MIT
Repository
github
Last release
4 years ago

rollup-plugin-terser Travis Build Status

Rollup plugin to minify generated es bundle. Uses terser under the hood.

Install

yarn add rollup-plugin-terser --dev
# Or with npm:
npm i rollup-plugin-terser --save-dev

Note: this package requires rollup@0.66 and higher (including rollup@2.0.0)

Usage

import { rollup } from "rollup";
import { terser } from "rollup-plugin-terser";

rollup({
  input: "main.js",
  plugins: [terser()],
});

Why named export?

  1. Module is a namespace. Default export often leads to function/component per file dogma and makes code less maintainable.
  2. Interop with commonjs is broken in many cases or hard to maintain.
  3. Show me any good language with default exports. It's historical javascriptism.

Options

⚠️ 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

Note: some terser options are set by the plugin automatically:

  • module: true is set when format is esm or es
  • toplevel: true is set when format is cjs

options.numWorkers: number

Amount of workers to spawn. Defaults to the number of CPUs minus 1.

Examples

Using as output plugin

// rollup.config.js
import { terser } from "rollup-plugin-terser";

export default {
  input: "index.js",
  output: [
    { file: "lib.js", format: "cjs" },
    { file: "lib.min.js", format: "cjs", plugins: [terser()] },
    { file: "lib.esm.js", format: "esm" },
  ],
};

Comments

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.

License

MIT © Bogdan Chadkin

wdsite-utils@cc-design/cestc-vue-scripts@monodrom/monodromcatlook@giveerr/rollpkgchomar-device-fingerprintingcherry-vue-uicheeyup7cheeyup8czt-app-componentsxiaopai-cliverdaccio-okta-auth@g7fe/g7-scriptsfelix-sum-reactadmin-bro-for-nextnexvel-component-librarynode-lib-dependenciesvuecomponents-testpackage@admin-bro/core@nuuji/js.configreact-css.ggjsxtal@aleksander_ciesielski/sinusbundlercodewonders_helperstsdx-extrasinusbundlerbappo-scriptsdiode-inspr-testdiode-testttdiode-inspr-test-test-testdiode-inspr-testtdiode-testdiode-test-test-diodeinspr-test-diode-testdiode-test-insprinspr-diode-testadmin-bro-jzmito-browser@ianlucas/service-analytics@outwalk/sablenew-vue-testnew-vue-test1@jleeson/toolchain-javascript@jleeson/toolchain-typescript@nuxt/deploy@ymatuhin/build@ymatuhin/uraniumlittle-dev-server@deity/falcon-clientcloud-archive-s3@yoteam/tool@passageid/passage-jsgsmlg-scriptslcs-axios@winexy/bbt-dsbridge@atomico/rollup-pack@atomico/buildbnc-gulp-multiple-pages@accurate-util/filter-util@victoriatong/common-componentplugin-web-modulesesnext-servers40-scriptsreact-mxgraph-editor@handwhittled/respond-clixdf-mini-libxdf-mini-lib-text@inspr/diodekd-ui-libskdui-libshlyc-components-webvigoworks.componentstooltipme-test2findhotel-sapimk-beter-clireact-new-first-libnpmlib-hayk-davlui2rollup-preset-vue@svazzle/config@shiluodexiaobaitu/zcutilskingsun-ui-expandmb-librairie-react@zlfgege/templatelightlib-ui@warleysouza/componentsnamefilter-lzmbussr-admin-bro@codewitchbella/microbundlevue-cli-plugin-dmaptakla-buildertakla-builder-rollup@ooxx87/uidemo@fle.cli/react-build@compensar/proveedores-builderefly-ui3.0gql_din_mod@donkeyclip/motorcortex-clidockersurface-threejs
7.0.2

4 years ago

5.3.1

4 years ago

7.0.1

4 years ago

7.0.0

4 years ago

6.1.0

4 years ago

6.0.1

4 years ago

6.0.0

4 years ago

5.3.0

5 years ago

5.2.0

5 years ago

5.1.3

5 years ago

5.1.2

5 years ago

5.1.1

5 years ago

5.1.0

5 years ago

5.0.0

5 years ago

4.0.4

6 years ago

4.0.3

6 years ago

4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.0.0

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago