パッケージの詳細

unplugin-remove

Talljack289.5kMIT1.0.3

Plugin to remove console.xx and debugger for Vite & Webpack & Esbuild & Rollup

unplugin, vite, webpack, rollup

readme

unplugin-remove

Auto remove console[log|warn|error|info|debug] and debugger in production mode.

Install

[npm|pnpm] i unplugin-remove -D

or

yarn add unplugin-remove -D

Demo

Example: playground/

<summary>Vite</summary>
ts // vite.config.ts import viteRemove from 'unplugin-remove/vite' export default defineConfig({ plugins: [ viteRemove({ /* options */ }), ], })
<summary>Rollup</summary>
ts // rollup.config.js import rollupRemove from 'unplugin-remove/rollup' export default { plugins: [ rollupRemove({ /* options */ }), ], }
<summary>Webpack</summary>
ts // webpack.config.js module.exports = { /* ... */ plugins: [ process.env.MODE === 'production' ? require('unplugin-remove/webpack')({ /* options */ }) : null, ].filter(Boolean), }
<summary>esbuild</summary>
ts // esbuild.config.js import { build } from 'esbuild' import esbuildRemove from 'unplugin-remove/esbuild' build({ plugins: [esbuildRemove()], })
<summary>Rspack ( <g-emoji class="g-emoji" alias="warning">⚠️</g-emoji> experimental)</summary>
ts // rspack.config.js const RspackPlugin = require('unplugin-remove/rspack').default module.exports = { plugins: [ new rspack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV), }), RspackPlugin(), ], }
<summary> Rolldown ( <g-emoji class="g-emoji" alias="warning">⚠️</g-emoji> experimental) </summary>
ts // rolldown.config.js import { defineConfig } from 'rolldown' import Rolldown from 'unplugin-remove/rolldown' export default defineConfig({ plugins: [ process.env.MODE === 'production' ? Rolldown() : null, ], })

Configuration

The following shows the default values of the configuration

Remove({
  // don't remove console.([log|warn|error|info|debug]) and debugger these module
  external: [],

  // remove console type of these module
  // enum: ['log', 'warn', 'error', 'info', 'debug']
  consoleType: ['log'],

  // filters for transforming targets
  include: [/\.[jt]sx?$/, /\.vue\??/],
  exclude: [/node_modules/, /\.git/]
})

CHANGELOG

You can see CHANGELOG here.

License

MIT License © 2022-PRESENT Talljack

更新履歴

CHANGELOG

1.0.2 - 2024-04-09

Fixes

  • Fix Rollup sourcemap incorrect when build issue.

Features

  • Add Vitest testes of remove debugger function.

1.0.1 - 2024-03-29

Features

  • Add Rspack plugin(experimental).
  • Add Rolldown plugin(experimental).

Fixes

  • Remove debugger when does't ends with ;.

1.0.0 - 2024-03-09

Fixes

  • Fix console bug when there are parentheses in parameters issue.

Features

  • Add Vitest testes of remove console function.