snowpack-plugin-terser
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

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

Package Sidebar

Install

npm i snowpack-plugin-terser

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

25.5 kB

Total Files

12

Last publish

Collaborators

  • jaredlunde