-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnuxt.config.ts
232 lines (217 loc) · 5.87 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
process.env.DEBUG = 'nuxt:*'
const pkg = require('./package')
const NODE_ENV = process.env.NODE_ENV
const API_HOST = process.env.API_HOST
const API_PORT = process.env.API_PORT
const PIXEL_ID = process.env.PIXEL_ID
const VF_HOST = process.env.VF_HOST
const RECAPTCHA_KEY = process.env.RECAPTCHA_KEY
const FRONTEND_NAME = process.env.KEY_FRONTEND_SERVER_NAME
const BACKEND_NAME = process.env.KEY_BACKEND_OAUTH_SERVER_NAME
let plugins = [
["component", {
"libraryName": "vant",
"libraryDirectory": "es",
style: false
}],
['import', { libraryName: 'ant-design-vue' }, 'ant-design-vue'],
["@babel/plugin-proposal-decorators", { legacy: true }],
["@babel/plugin-proposal-class-properties", { loose: true }]
]
// 如果为正式服则添加去除console
// if (process.env.NODE_ENV === 'production') {
// plugins.push('transform-remove-console')
// }
module.exports = {
mode: 'universal',
buildDir: (NODE_ENV ? `${NODE_ENV}` : '') + '_nuxt',
debug: true,
render: {
http2: {
push: true
},
bundleRenderer: {
/**
* nuxt是基于vue的ssr解决方案,可以是使用vue语法完成前后端的同构。
* 然而在与传统纯字符串拼接的ssr方案相比,性能就没那么好了,
* nuxt需要在服务端生成虚拟dom,然后再序列化出HTML字符串,
* 我们常说nodejs的高性能指的是异步IO操作频繁的场景而非CPU操作密集的场景,
* 毕竟nodejs是运行在单线程下的,在涉及到高并发的场景下,性能就会有所下降,可以考虑采用合理的缓存策略
* 会引发问题:https://visonsoft.cn/2018/07/05/vue-nuxt-ssr/
* 不适用:style的module冲突
*/
// cache: new LRU({
// max: 10,
// maxAge: 1000 * 60 * 15
// })
}
},
env: {
frontendUrl: FRONTEND_NAME ? `https://${FRONTEND_NAME}` : '',//前端域名
backendUrl: BACKEND_NAME ? `https://${BACKEND_NAME}` : '',//fb登录用的重定向服务端域名
ga_id: process.env.GA_ID,//谷歌分析ID
recaptcha_key: RECAPTCHA_KEY,
NODE_ENV: NODE_ENV,//环境服
facebookId: process.env.APP_FACEBOOK_ID_KEY,//fb id
version: pkg.version
},
// serverMiddleware: [
// '~/server/index.ts'
// ],
router: {
middleware: 'authenticated'
},
/*
** Headers of the page
*/
head: {
title: pkg.name,
meta: [
{ charset: "utf-8" },
{
name: "viewport",
content: "width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover"
},
{ name: "apple-mobile-web-app-status-bar-style", content: "black" },
{ name: "apple-mobile-web-app-capable", content: "yes" },
{ name: "format-detection", content: "telephone=no" },
{ name: "apple-mobile-web-app-title", content: "bidogoo" },
{ httpEquiv: "Access-Control-Allow-Origin", content: "*" },
{ httpEquiv: "Pragma", content: "no-cache" },
{ httpEquiv: "Expires", content: "0" },
{ httpEquiv: "Cache-Control", content: "no-cache" }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
]
},
/*
** Customize the progress-bar color
*/
loading: { color: '#409EFF' },
/*
** Global CSS
*/
css: [
{ src: "~/assets/scss/common.scss", lang: 'scss' },
'ant-design-vue/dist/antd.css'
],
styleResources: {
scss: [
"~/assets/scss/theme.scss",
"~/assets/scss/mixin.scss",
],
},
/*
** Build configuration
*/
build: {
extractCSS: process.env.NODE_ENV != 'development',
publicPath: VF_HOST ? '//' + VF_HOST + '/_nuxt/' : '/_nuxt/',
/*
** You can extend webpack config here
*/
extend(config, { isDev, isServer }) {
if (isDev && process.client) {
config.module.rules.push({
test: /\.ts$/,
exclude: [/node_modules/, /vendor/, /\.nuxt/],
loader: 'ts-loader',
options: {
fix: true
}
})
}
},
babel: {
"plugins": plugins
},
postcss: {
plugins: {
'postcss-pxtorem': {
rootValue: 16,
unitPrecision: 5,
propList: ['*'],
selectorBlackList: [],
replace: true,
mediaQuery: false,
minPixelValue: 1
}
}
}
},
transition: {
name: "page",
mode: "out-in"
},
/*
** Plugins to load before mounting the App
*/
plugins: [
"~/plugins/i18n.ts",
{src: '~/plugins/antd.ts', ssr: true},
],
/*
** Nuxt.js modules
*/
modules: [
'@nuxtjs/style-resources',
"@nuxtjs/apollo",
"@nuxtjs/proxy",
'@nuxtjs/sentry',
"nuxt-facebook-pixel",
[
'nuxt-i18n',
{
locales: [
{
code: "th",
iso: "th-TH",
file: 'th-TH.js'
},
{
code: "en",
iso: "en-US",
file: 'en-US.js'
},
{
code: "zh",
iso: "zh-CN",
file: 'zh-CN.js'
}
],
strategy: 'prefix_except_default',//防止重复的路由名称问题
lazy: true,
langDir: 'locales/bidogoo/',
vueI18nLoader: true,
defaultLocale: "th",
detectBrowserLanguage: {
useCookie: true,
alwaysRedirect: false,
cookieKey: "i18n_redirected",
fallbackLocale: "th",
},
seo: false,
parsePages: false,
encodePaths: true,
}]
],
apollo: {
tokenName: "token",
tokenExpires: 30,
includeNodeModules: true,
authenticationType: "",
clientConfigs: {
default: "~/graphql/apollo-config.ts"
},
// optional
errorHandler: '~/plugins/apollo-error-handler.ts',
},
proxy: {
'/zh/api': { target: (API_HOST ? `http://${API_HOST}:${API_PORT}` : 'http://www.baidu.com') + `/zh/api`, pathRewrite: { "^/zh/api": "" } },
},
"facebook-pixel": {
enable: true,
id: PIXEL_ID + ''
}
}