source: frontend/node_modules/rollup-plugin-terser/README.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.6 KB
Line 
1# rollup-plugin-terser [![Travis Build Status][travis-img]][travis]
2
3[travis-img]: https://travis-ci.org/TrySound/rollup-plugin-terser.svg
4[travis]: https://travis-ci.org/TrySound/rollup-plugin-terser
5
6[Rollup](https://github.com/rollup/rollup) plugin to minify generated es bundle. Uses [terser](https://github.com/fabiosantoscode/terser) under the hood.
7
8## Install
9
10```sh
11yarn add rollup-plugin-terser --dev
12# Or with npm:
13npm i rollup-plugin-terser --save-dev
14```
15
16_Note: this package requires rollup@0.66 and higher (including rollup@2.0.0)_
17
18## Usage
19
20```js
21import { rollup } from "rollup";
22import { terser } from "rollup-plugin-terser";
23
24rollup({
25 input: "main.js",
26 plugins: [terser()],
27});
28```
29
30## Why named export?
31
321. Module is a namespace. Default export often leads to function/component per file dogma and makes code less maintainable.
332. Interop with commonjs is broken in many cases or hard to maintain.
343. Show me any good language with default exports. It's historical javascriptism.
35
36## Options
37
38> ⚠️ **Caveat:** any function used in options object cannot rely on its surrounding scope, since it is executed in an isolated context.
39
40```js
41terser(options);
42```
43
44`options` - [terser API options](https://github.com/fabiosantoscode/terser#minify-options)
45
46Note: some terser options are set by the plugin automatically:
47
48- `module: true` is set when `format` is `esm` or `es`
49- `toplevel: true` is set when `format` is `cjs`
50
51`options.numWorkers: number`
52
53Amount of workers to spawn. Defaults to the number of CPUs minus 1.
54
55## Examples
56
57### Using as output plugin
58
59```js
60// rollup.config.js
61import { terser } from "rollup-plugin-terser";
62
63export default {
64 input: "index.js",
65 output: [
66 { file: "lib.js", format: "cjs" },
67 { file: "lib.min.js", format: "cjs", plugins: [terser()] },
68 { file: "lib.esm.js", format: "esm" },
69 ],
70};
71```
72
73### Comments
74
75If you'd like to preserve comments (for licensing for example), then you can specify a function to do this like so:
76
77```js
78terser({
79 output: {
80 comments: function (node, comment) {
81 var text = comment.value;
82 var type = comment.type;
83 if (type == "comment2") {
84 // multiline comment
85 return /@preserve|@license|@cc_on/i.test(text);
86 }
87 },
88 },
89});
90```
91
92Alternatively, you can also choose to keep all comments (e.g. if a licensing header has already been prepended by a previous rollup plugin):
93
94```js
95terser({
96 output: {
97 comments: "all",
98 },
99});
100```
101
102See [Terser documentation](https://github.com/fabiosantoscode/terser#terser) for further reference.
103
104# License
105
106MIT © [Bogdan Chadkin](mailto:trysound@yandex.ru)
Note: See TracBrowser for help on using the repository browser.