snowpack-plugin-terser

Use Terser to minify JavaScript in production Snowpack apps

Usage no npm install needed!

<script type="module">
  import snowpackPluginTerser from 'https://cdn.skypack.dev/snowpack-plugin-terser';
</script>

README


snowpack-plugin-terser

Use Terser to minify JavaScript in production Snowpack apps

# NOTE: terser is a peer dependency
npm i terser snowpack-plugin-terser

Types Build status NPM Version MIT License


Why do this?

While Snowpack has a minify option built in, it only uses esbuild's minification. In doing so it misses many optimizations that are caught by Terser.

When to use this

You should only use this if you aren't already using a bundler (Webpack, Parcel, Rollup) to build your production site.

Quick start

// snowpack.config.js
module.exports = {
  buildOptions: {
    minify: false,
  },
  plugins: [
    [
      'snowpack-plugin-terser',
      {
        /**
         * @see Plugin Options below
         */
        terserOptions: {
          compress: {
            arguments: true,
            passes: 2,
            unsafe_arrows: true,
          },
        },
      },
    ],
  ],
}

Plugin Options

export interface SnowpackPluginTerserOptions {
  /**
   * An array of glob patterns for files you want to explicitly include
   * for Terser minification. By default, all JavaScript files are included.
   */
  include?: string[]
  /**
   * An array of glob patterns for files you want to exclude from
   * Terser minification
   */
  exclude?: string[]
  /**
   * Terser minify() options passed directly to Terser
   * @see https://github.com/terser/terser#minify-options
   *
   * @default {
   *   module: true,
   *   toplevel: true,
   *   compress: {
   *     ecma: 2016,
   *   },
   *   format: {
   *     ecma: 2016
   *   }
   * }
   */
  terserOptions?: terser.MinifyOptions
}

LICENSE

MIT