UNPKG

2.73 kBMarkdownView Raw
1# rollup-plugin-closure-compiler
2
3Leverage [Closure Compiler](https://developers.google.com/closure/compiler/) to minify and optimize JavaScript with [Rollup](https://rollupjs.org/guide/en).
4
5Generally Closure Compiler will produce superior minification than other projects, but historically has been more difficult to use. The goal of this plugin is to reduce this friction.
6
7## Installation
8
9```bash
10npm install @ampproject/rollup-plugin-closure-compiler --save-dev
11```
12
13## Usage
14
15Invoke Closure Compiler from your Rollup configuration.
16
17```js
18// rollup.config.js
19import compiler from '@ampproject/rollup-plugin-closure-compiler';
20
21export default {
22 input: 'main.js',
23 output: {
24 file: 'bundle.js',
25 format: 'iife',
26 },
27 plugins: [
28 compiler(),
29 ],
30}
31```
32
33If you would like to provide additional [flags and options](https://github.com/google/closure-compiler/wiki/Flags-and-Options) to Closure Compiler, pass them via key-value pairs.
34
35```js
36// rollup.config.js
37import compiler from '@ampproject/rollup-plugin-closure-compiler';
38
39export default {
40 input: 'main.js',
41 output: {
42 file: 'bundle.js',
43 format: 'iife',
44 },
45 plugins: [
46 compiler({
47 formatting: 'PRETTY_PRINT'
48 }),
49 ],
50}
51```
52
53### Automatic Closure Configuration
54
55This plugin will modify the enable the `assume_function_wrapper` output option for Closure Compiler when `es` format is specifed to Rollup. **Note**: This is overrideable via passed flags and options.
56
57```js
58// rollup.config.js
59import compiler from '@ampproject/rollup-plugin-closure-compiler';
60
61export default {
62 input: 'main.js',
63 output: {
64 file: 'bundle.js',
65 format: 'es',
66 },
67 plugins: [
68 compiler(),
69 ],
70}
71```
72
73If your Rollup configuration outputs an IIFE format bundle with a specified name, this plugin will add an extern to ensure the name does not get mangled. **Note**: This is overrideable via passed flags and options.
74
75```js
76// rollup.config.js
77import compiler from '@ampproject/rollup-plugin-closure-compiler';
78
79export default {
80 input: 'main.js',
81 output: {
82 file: 'bundle.js',
83 format: 'iife',
84 name: 'MyAwesomeThing'
85 },
86 plugins: [
87 compiler(),
88 ],
89}
90```
91
92## Security disclosures
93
94The AMP Project accepts responsible security disclosures through the [Google Application Security program](https://www.google.com/about/appsecurity/).
95
96## Code of conduct
97
98The AMP Project strives for a positive and growing project community that provides a safe environment for everyone. All members, committers and volunteers in the community are required to act according to the [code of conduct](.github/CODE_OF_CONDUCT.md).
99
100## License
101
102rollup-plugin-closure-compiler is licensed under the [Apache License, Version 2.0](LICENSE).