Skip to content
This repository was archived by the owner on Jul 10, 2019. It is now read-only.

Commit 241b451

Browse files
committed
chore(nuxt.config.ts): add drop_console when to production build
1 parent 167871a commit 241b451

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Diff for: nuxt.config.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
mode: 'universal',
1212
srcDir: 'src/',
1313

14+
// ビルド時に渡される env の値は、ここに記載することで文字列に置換される
1415
env: {
1516
NODE_ENV: process.env.NODE_ENV,
1617
BUILD_ENV: process.env.BUILD_ENV,
@@ -42,6 +43,7 @@ module.exports = {
4243
const vueLoader: any = config.module!.rules.find(
4344
(rule): boolean => rule.loader === 'vue-loader'
4445
)
46+
// 特殊なアトリビュートでも webpack の require がかまされるようにする
4547
vueLoader.options.transformAssetUrls = {
4648
video: ['src', 'poster'],
4749
source: 'src',
@@ -53,7 +55,16 @@ module.exports = {
5355
},
5456
extractCSS: isProduction,
5557
// https://qiita.com/toaru/items/0690a9110c94052bb479
56-
hardSource: true
58+
hardSource: true,
59+
terser: {
60+
terserOptions: {
61+
compress: {
62+
// console 系を削除する
63+
// https://www.lancard.com/blog/2019/04/05/delete_console-log_at_nuxt_build/
64+
drop_console: process.env.envName === 'production' // eslint-disable-line @typescript-eslint/camelcase
65+
}
66+
}
67+
}
5768
},
5869

5970
// https://ja.nuxtjs.org/faq/host-port/

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"dev": "cross-env NODE_ENV=development BUILD_ENV=local nuxt",
99
"build": "nuxt build --no-lock",
1010
"build:static": "nuxt build --spa --no-lock",
11-
"build:local": "cross-env NODE_ENV=production BUILD_ENV=local nuxt build --no-lock",
11+
"build:local": "cross-env NODE_ENV=production BUILD_ENV=local envName=local nuxt build --no-lock",
1212
"build:docker": "cross-env NODE_ENV=production nuxt build --no-lock",
1313
"start": "nuxt start",
1414
"lint": "eslint --ext .js,.ts,.vue --ignore-path .gitignore .",

0 commit comments

Comments
 (0)