Use Terser to minify JavaScript in production Snowpack apps
# NOTE: terser is a peer dependency
npm i terser snowpack-plugin-terser
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.
You should only use this if you aren't already using a bundler (Webpack, Parcel, Rollup) to build your production site.
// 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,
},
},
},
],
],
}
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
}
MIT