0.0.1 • Published 9 months ago

vite-plugin-strip-comments v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

vite-plugin-strip-comments

Coverage Status ci NPM Version NPM Downloads typescript version vitest version vite version

A simple Vite plugin for stripping comments in your production code. Some comments just don't get removed no matter what minify options you set, especially /* istanbul ignore */ flags. Also keep in mind this is experimental, the configuration doesn't work properly, it always removes ALL comments, so use with caution.

Install

pnpm install -D vite-plugin-strip-comments
yarn add -D vite-plugin-strip-comments
npm install -D vite-plugin-strip-comments
deno install -D npm:vite-plugin-strip-comments@latest

Usage

// vite.config.mts
import stripComments from 'vite-plugin-strip-comments';

export default defineConfig({
  plugins: [
    // ... other plugins
    stripComments({ type: 'istanbul' }),
  ],
});

Options

  • type: "none" | "keep-legal" | "istanbul" (default) - changes the behavior of the transform function
    • none removes all comments
    • keep-legal remove all commments except those which contain @legal or @license, a very good practice to allow open source to shine yes?
    • istanbul (default) only remove comments that target istanbul code coverage instrumentation (EG: /* istanbul ignore else @preserve */)

Contributions

  • Found a problem, report the problem. Thank you!
  • Found a fix? Clone, install, apply fix and commit. Thank you!

License

vite-plugin-strip-comments is released under the MIT License.

0.0.1

9 months ago