| 1 |
[npm]: https://img.shields.io/npm/v/@rollup/plugin-terser |
| 2 |
[npm-url]: https://www.npmjs.com/package/@rollup/plugin-terser |
| 3 |
[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-terser |
| 4 |
[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-terser |
| 5 |
|
| 6 |
[![npm][npm]][npm-url] |
| 7 |
[![size][size]][size-url] |
| 8 |
[](https://liberamanifesto.com) |
| 9 |
|
| 10 |
# @rollup/plugin-terser |
| 11 |
|
| 12 |
🍣 A Rollup plugin to generate a minified bundle with terser. |
| 13 |
|
| 14 |
## Requirements |
| 15 |
|
| 16 |
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v2.0+. |
| 17 |
|
| 18 |
## Install |
| 19 |
|
| 20 |
Using npm: |
| 21 |
|
| 22 |
```console |
| 23 |
npm install @rollup/plugin-terser --save-dev |
| 24 |
``` |
| 25 |
|
| 26 |
## Usage |
| 27 |
|
| 28 |
Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin: |
| 29 |
|
| 30 |
```typescript |
| 31 |
import terser from '@rollup/plugin-terser'; |
| 32 |
|
| 33 |
export default { |
| 34 |
input: 'src/index.js', |
| 35 |
output: { |
| 36 |
dir: 'output', |
| 37 |
format: 'cjs' |
| 38 |
}, |
| 39 |
plugins: [terser()] |
| 40 |
}; |
| 41 |
``` |
| 42 |
|
| 43 |
Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the [API](https://www.rollupjs.org/guide/en/#javascript-api). |
| 44 |
|
| 45 |
## Options |
| 46 |
|
| 47 |
The plugin accepts a terser [Options](https://github.com/terser/terser#minify-options) object as input parameter, |
| 48 |
to modify the default behaviour. |
| 49 |
|
| 50 |
In addition to the `terser` options, it is also possible to provide the following options: |
| 51 |
|
| 52 |
### `maxWorkers` |
| 53 |
|
| 54 |
Type: `Number`<br> |
| 55 |
Default: `undefined` |
| 56 |
|
| 57 |
Instructs the plugin to use a specific amount of cpu threads. |
| 58 |
|
| 59 |
```typescript |
| 60 |
import terser from '@rollup/plugin-terser'; |
| 61 |
|
| 62 |
export default { |
| 63 |
input: 'src/index.js', |
| 64 |
output: { |
| 65 |
dir: 'output', |
| 66 |
format: 'cjs' |
| 67 |
}, |
| 68 |
plugins: [ |
| 69 |
terser({ |
| 70 |
maxWorkers: 4 |
| 71 |
}) |
| 72 |
] |
| 73 |
}; |
| 74 |
``` |
| 75 |
|
| 76 |
## Meta |
| 77 |
|
| 78 |
[CONTRIBUTING](/.github/CONTRIBUTING.md) |
| 79 |
|
| 80 |
[LICENSE (MIT)](/LICENSE) |