2
2

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 3 years have passed since last update.

Laravel Mixで圧縮時にconsole.logを削除してconsole.errorを残す

Posted at

下記をwebpack.mix.jsに追記すると、production用 (NODE_ENV=production) にビルドするだけでpure_funcsで指定しているconsole.debugconsole.logを削除してくれる。

if (mix.inProduction()) {
    mix.options({
        terser: {
            terserOptions: {
                compress: {
                    // Drop these function calls. Keep console.error and etc.
                    pure_funcs: [
                        'console.debug',
                        'console.log'
                    ]
                }
            }
        }
    });
}

上記設定だと、console.wanrconsole.errorは削除されずに残る。

console.*をすべて削除したい場合はpure_funcsを使う代わりに下記でOK。

if (mix.inProduction()) {
    mix.options({
        terser: {
            terserOptions: {
                compress: {
                    drop_console: true // This drops all console.* calls
                }
            }
        }
    });
}

Laravel Mix 5.0.9で確認。

参考: https://github.com/webpack-contrib/terser-webpack-plugin/issues/57

2
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?