TylorS / snowpack-plugin-optimize

An alternative optimization plugin for snowpack w/ sourceMap support
5 stars 0 forks source link

snowpack-plugin-optimize

Makes use of terser, csso, and html-minifier to provide minification of your JS, CSS, and HTML files respectively.

Features

We're open to new kinds of optimizations, open an issue and lets talk!

Non-Features

Install

npm i --save-dev snowpack-plugin-optimize

yarn add -d snowpack-plugin-optimize

Usage

// snowpack.config.js

module.exports = {
  ...config,
  plugins: [
    [
      'snowpack-plugin-optimize',
      // Entirely optional object. Showing default values
      {
        // Turn JS minification with Terser on/off
        minifyJs?: true
        // A deep merge is performed with these defaults.
        // @see Terser configuration https://github.com/terser/terser#minify-options-structure
        jsOptions?: {
          module: true,
          toplevel: true,
          sourceMap: true,
          nameCache,
          compress: {
            ecma: 2019,
          },
          format: {
            ecma: 2019,
          },
        },
        // Adds modulepreload links to potentially improve your module dependency load times
        modulePreload?: true,
        minifyCss?: true,
        // A merge is performed with these default
        // @see CSSO configuration https://github.com/css/csso#minifysource-options
        cssOptions?: {
          sourceMap: true,
          filename: path.basename(file),
        },
        minifyHtml?: true,
        // A merge is performed with these defaults
        // @see html-minifier configuration https://github.com/kangax/html-minifier#options-quick-reference
        htmlOptions?: {
          collapseWhitespace: true,
          keepClosingSlash: true,
          removeComments: true,
        },
      }
    ]
  ]
}