1. @ampproject/rollup-plugin-closure-compiler
Rollup + Google Closure Compiler
@ampproject/rollup-plugin-closure-compiler
Package: @ampproject/rollup-plugin-closure-compiler
Created by: ampproject
Last modified: Sun, 12 Jun 2022 14:39:55 GMT
Version: 0.27.0
License: Apache-2.0
Downloads: 11,845
Repository: https://github.com/ampproject/rollup-plugin-closure-compiler

Install

npm install @ampproject/rollup-plugin-closure-compiler
yarn add @ampproject/rollup-plugin-closure-compiler

rollup-plugin-closure-compiler

Leverage Closure Compiler to minify and optimize JavaScript with Rollup.

Generally 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.

Installation

 npm install @ampproject/rollup-plugin-closure-compiler --save-dev

Usage

Invoke Closure Compiler from your Rollup configuration.

 // rollup.config.js
import compiler from '@ampproject/rollup-plugin-closure-compiler';

export default {
  input: 'main.js',
  output: {
    file: 'bundle.js',
    format: 'iife',
  },
  plugins: [
    compiler(),
  ],
}

If you would like to provide additional flags and options to Closure Compiler, pass them via key-value pairs.

 // rollup.config.js
import compiler from '@ampproject/rollup-plugin-closure-compiler';

export default {
  input: 'main.js',
  output: {
    file: 'bundle.js',
    format: 'iife',
  },
  plugins: [
    compiler({
      formatting: 'PRETTY_PRINT'
    }),
  ],
}

Automatic Closure Configuration

This 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.

 // rollup.config.js
import compiler from '@ampproject/rollup-plugin-closure-compiler';

export default {
  input: 'main.js',
  output: {
    file: 'bundle.js',
    format: 'es',
  },
  plugins: [
    compiler(),
  ],
}

If 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.

 // rollup.config.js
import compiler from '@ampproject/rollup-plugin-closure-compiler';

export default {
  input: 'main.js',
  output: {
    file: 'bundle.js',
    format: 'iife',
    name: 'MyAwesomeThing'
  },
  plugins: [
    compiler(),
  ],
}

Security disclosures

The AMP Project accepts responsible security disclosures through the Google Application Security program.

Code of conduct

The 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.

License

rollup-plugin-closure-compiler is licensed under the Apache License, Version 2.0.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code