2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

<備忘録>Viteで作ったReact app内の全てのconsole.logを一瞬でdeactivateする方法

Last updated at Posted at 2023-10-09

React内のconsole.logをbuild時に一括deactivate

サーバーにアプリを上げる前に、console.logを一括してディアクティヴェート出来る超便利な方法があるんだけど、いつもやり方を忘れるので、備忘録としてログ。

1,rollup-plugin-strip をインストール

npm install @rollup/plugin-strip --save-dev

2、vite.configのdefineConfig()を編集

import strip from '@rollup/plugin-strip';

export default defineConfig({
  plugins: [
    react(),
    strip({
      // remove all console.log calls
      include: ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx'],
      functions: ['console.log'],
    }),
  ],
})

たったこれだけで、Reactをbuild時にReact内の全てのconsole.logをワイプアウト。
超便利。*ビルド時にconsole.logは省かれるだけでファイルにはそのまま残ります。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?