This repository was archived by the owner on Jul 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathnuxt.config.ts
244 lines (219 loc) · 6.43 KB
/
nuxt.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
import NuxtConfiguration from '@nuxt/config'
import {
Configuration as WebpackConfiguration,
Options as WebpackOptions,
Plugin as WebpackPlugin
} from 'webpack'
import routers from './src/routers/'
const pkg = require('./package')
// Docker から渡ってくるが Nuxt アプリではなく nuxt.config で必要な環境変数
const {
// Google Tag Manager
gtmContainerId = 'GTM-56L94CP'
} = process.env
const config: NuxtConfiguration = {
mode: 'universal',
srcDir: 'src/',
/**
* 環境変数
* ビルド時に渡される env の値は、ここに記載することで文字列に置換される
*/
env: {
// Nuxt のビルドで必要な環境変数
NODE_ENV: process.env.NODE_ENV || '',
BUILD_ENV: process.env.BUILD_ENV || '',
// Docker から渡ってくる Nuxt アプリで使う環境変数
envName: process.env.envName || '',
internalEndpointUrl: process.env.internalEndpointUrl || '',
externalEndpointUrl: process.env.externalEndpointUrl || ''
},
/**
* Build configuration
* webpack のビルドに関する設定はここに書く
*/
build: {
// vue-devtools を許可するかどうかを設定します
// https://ja.nuxtjs.org/api/configuration-build/#devtools
devtools: true,
loaders: {
// https://ja.nuxtjs.org/faq/webpack-audio-files/
vue: {
// 特殊なアトリビュートでも webpack の require がかまされるようにする
transformAssetUrls: {
audio: 'src',
video: ['src', 'poster'],
source: 'src',
img: ['src', 'data-src'],
'lazy-image': 'src'
}
}
},
/**
* You can extend webpack config here
*/
extend(
config: WebpackConfiguration,
ctx: {
isDev: boolean
isClient: boolean
isServer: boolean
loaders: any
}
): void {
// Run ESLint on save
if (ctx.isDev && process.client) {
if (config.module) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
})
}
}
// https://ja.nuxtjs.org/faq/webpack-audio-files/
config.module!.rules.push({
test: /\.(ogg|mp3|wav|mpe?g)$/i,
loader: 'file-loader',
options: {
name: '[path][name].[ext]'
}
})
},
// extractCSS: isProduction,
// ビルドを爆速にする
// https://qiita.com/toaru/items/0690a9110c94052bb479
hardSource: true,
terser: {
terserOptions: {
compress: {
// console 系を削除する
// https://www.lancard.com/blog/2019/04/05/delete_console-log_at_nuxt_build/
// drop_console: process.env.envName === 'production' // eslint-disable-line @typescript-eslint/camelcase
}
}
}
},
// https://ja.nuxtjs.org/faq/host-port/
server: {
port: 4000,
// 他のパソコンから IP でつながるように host を変更
host: '0.0.0.0' // デフォルト: localhost
},
/**
* Headers of the page
*/
head: {
title: pkg.name,
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: pkg.description }
],
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }]
},
/**
* Customize the progress-bar color
*/
loading: {
color: 'blue',
height: '5px'
},
// ローディングを使わない場合はここを false
// loading: false,
/**
* Global CSS
* 他の scss ファイルに依存しない scss はこちらに
*/
css: [
'@/assets/styles/reset.scss',
'@/assets/styles/main.scss',
'swiper/dist/css/swiper.css'
],
/**
* Plugins to load before mounting the App
*/
plugins: [
'@/plugins/constants-inject.ts',
'@/plugins/env-inject.ts',
'@/plugins/libraries/axios.ts',
'@/plugins/libraries/vue-lazyload.ts',
'@/plugins/locale/i18n.ts',
{ src: '@/plugins/libraries/vue-carousel.ts', ssr: false },
{ src: '@/plugins/libraries/vue-awesome-swiper', mode: 'client' }
],
/*
** Nuxt.js modules
*/
modules: [
// Doc: https://axios.nuxtjs.org/usage
'@nuxtjs/axios',
'@nuxtjs/pwa',
// https://github.com/nuxt-community/style-resources-module/
'@nuxtjs/style-resources',
// https://github.com/nuxt-community/sentry-module
'@nuxtjs/sentry',
// https://github.com/potato4d/nuxt-client-init-module
// https://qiita.com/potato4d/items/cc5d8ea24949e86f8a5b
'nuxt-client-init-module',
// https://github.com/nuxt-community/modules/tree/master/packages/google-tag-manager
[
'@nuxtjs/google-tag-manager',
{
id: gtmContainerId,
layer: 'dataLayer',
pageTracking: false,
dev: !gtmContainerId,
query: {}
}
],
// https://github.com/samtgarson/nuxt-env
[
'nuxt-env',
{
keys: [
'TEST_ENV_VAR', // Basic usage—equivalent of { key: 'TEST_ENV_VAR' }
{ key: 'RUNTIME_ENV', default: 'defaultValue' } // Specify a default value
]
}
]
],
sentry: {
dsn: 'https://[email protected]/1423878', // Enter your project's DSN here
config: {} // Additional config
},
/**
* Axios module configuration
*/
axios: {
// See https://github.com/nuxt-community/axios-module#options
},
router: {
// リロードのタイミングでは SSR 側で実行される
// ルーティングの度に CSR 側で実行される
// ログインの必要のない画面でも middleware が実行されるので注意が必要
// middleware: 'check-auth',
middleware: 'i18n',
extendRoutes(routes: any, resolve: any): void {
// https://ja.nuxtjs.org/api/configuration-router/#extendroutes
if (routers && routers.length > 0) {
for (const fn of routers) {
routes.push(fn(resolve))
}
}
}
},
/**
* Sass の @extend を使う場合はこのパスの scss ファイルに CSS クラスを書く
*/
styleResources: {
scss: ['@/assets/styles/components/**/*.scss']
},
/**
* nuxt サーバーを API サーバーとして使う場合のミドルウェアを定義する
*/
serverMiddleware: [
{ path: '/api/healthcheck', handler: '~/api/healthcheck.js' }
]
}
module.exports = config