forked from surmon-china/surmon.me
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nuxt.config.js
executable file
·232 lines (229 loc) · 7.35 KB
/
nuxt.config.js
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
/**
* @file App config / Commonjs module
* @module nuxt.config
* @author Surmon <https://github.com/surmon-china>
*/
const path = require('path')
const webpack = require('webpack')
const apiConfig = require('./api.config')
const i18nConfig = require('./i18n.config')
const { isProdMode, isDevMode } = require('./environment')
const htmlLang = i18nConfig.default || 'zh'
const htmlSlogan = htmlLang === 'zh' ? '欢喜勇猛,向死而生' : 'Talk is cheap. Show me the code.'
module.exports = {
mode: 'universal',
dev: isDevMode,
env: {
baseUrl: apiConfig.baseUrl,
HOST_URL: apiConfig.socketHost
},
loading: {
color: '#0088f5'
},
cache: {
max: 100,
maxAge: 1000 * 60 * 15
},
build: {
// analyze: true,
// 设置 cdn 地址
publicPath: apiConfig.cdnUrl + '/_nuxt/',
postcss: {
plugins: {
'postcss-custom-properties': {
warnings: false
}
}
},
// 单独提取 css
extractCSS: true,
optimization: {
splitChunks: {
cacheGroups: {
/*
styles: {
name: 'styles',
test: /\.(css|vue)$/,
chunks: 'all',
enforce: true
}
*/
}
}
},
// 对webpack的扩展
extend(webpackConfig, { isDev, isClient }) {
// 处理 Swiper4 下的 dom7 模块的语法问题
webpackConfig.resolve.alias.dom7$ = 'dom7/dist/dom7.js'
webpackConfig.resolve.alias.swiper$ = 'swiper/dist/js/swiper.js'
if (isDev && isClient) {
// Run ESLINT on save
webpackConfig.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: [/(node_modules)/, /underscore-simple/, /webrtc/]
})
}
if (isProdMode) {
const vueLoader = webpackConfig.module.rules.find(loader => loader.loader === 'vue-loader')
if (vueLoader) {
// 处理 Template 中的 cdn 地址
// vueLoader.options.loaders.html = path.resolve(__dirname, './extend/html-cdn-loader')
// 处理 CSS 中的 cdn 地址
const vueLoaders = vueLoader.options.loaders
for (const cssLoader in vueLoaders) {
if (Array.isArray(vueLoaders[cssLoader])) {
const targetLoader = vueLoaders[cssLoader].find(loader => loader.loader === 'css-loader')
targetLoader && (targetLoader.options.root = apiConfig.cdnUrl)
}
}
}
}
},
// 将重复引用的(第三方/自有)模块添加到vendor.bundle.js
vendor: [
'axios',
'howler',
'swiper',
'marked',
'gravatar',
'highlight.js',
// 'particles.js',
'simplewebrtc',
'bezier-easing',
'socket.io-client'
],
maxChunkSize: 350000,
// 为 JS 和 Vue 文件定制 babel 配置。https://nuxtjs.org/api/configuration-build/#analyze
babel: {
presets({ isServer }) {
return [
[
'@nuxtjs/babel-preset-app',
{ targets: isServer ? { node: '10.4.0' } : { chrome: 69 } }
]
]
},
plugins: [
'@babel/plugin-transform-runtime',
'@babel/plugin-transform-async-to-generator'
],
comments: true
},
styleResources: {
scss: './assets/sass/init.scss',
options: {}
}
},
plugins: [
{ src: '~/plugins/vue-extend.js' },
{ src: '~/plugins/loaded-task.js' },
{ src: '~/plugins/marked.js' },
{ src: '~/plugins/gravatar.js' },
{ src: '~/plugins/highlight.js' },
{ src: '~/plugins/adsense.js', ssr: false },
{ src: '~/plugins/swiper.js', ssr: false },
{ src: '~/plugins/analytics.js', ssr: false },
{ src: '~/plugins/emoji-233333.js', ssr: false },
{ src: '~/plugins/image-popup.js', ssr: false },
{ src: '~/plugins/copy-right.js', ssr: false },
// { src: '~/plugins/particles.js', ssr: false }
],
head: {
title: `Surmon.me - ${htmlSlogan}`,
titleTemplate: '%s | Surmon.me',
htmlAttrs: {
xmlns: 'http://www.w3.org/1999/xhtml',
lang: htmlLang
},
meta: [
{ charset: 'utf-8' },
{ 'http-equiv': 'cleartype', content: 'on' },
{ 'http-equiv': 'x-dns-prefetch-control', content: 'on' },
{ name: 'author', content: '[email protected]' },
{ name: 'MobileOptimized', content: '320' },
{ name: 'HandheldFriendly', content: 'True' },
{ name: 'apple-mobile-web-app-capable', content: 'yes' },
{ name: 'apple-mobile-web-app-status-bar-style', content: 'black' },
{ name: 'apple-mobile-web-app-title', content: 'Surmon.me' },
{ name: 'apple-touch-icon', content: '/static/icon.png' },
{ name: 'msapplication-TileImage', content: '/static/icon.png' },
{ name: 'msapplication-TileColor', content: '#0088f5' },
{ name: 'format-detection', content: 'telephone=no' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1.0, user-scalable=no' },
{ hid: 'keywords', name: 'keywords', content: 'Surmon,马赐崇,司马萌,Vue开发者,前端技术开发,javascript技术' },
{ hid: 'description', name: 'description', content: '凡心所向,素履所往,生如逆旅,一苇以航' }
],
link: [
{ rel: 'dns-prefetch', href: '//surmon.me' },
{ rel: 'dns-prefetch', href: '//api.surmon.me' },
{ rel: 'dns-prefetch', href: '//cdn.surmon.me' },
{ rel: 'dns-prefetch', href: '//static.surmon.me' },
{ rel: 'dns-prefetch', href: '//gravatar.surmon.me' },
{ rel: 'dns-prefetch', href: '//at.alicdn.com' },
{ rel: 'dns-prefetch', href: '//fonts.gstatic.com' },
{ rel: 'dns-prefetch', href: '//adservice.google.com' },
{ rel: 'dns-prefetch', href: '//fonts.googleapis.com' },
{ rel: 'dns-prefetch', href: '//googleads.g.doubleclick.net' },
{ rel: 'dns-prefetch', href: '//www.google-analytics.com' },
{ rel: 'dns-prefetch', href: '//tpc.googlesyndication.com' },
{ rel: 'dns-prefetch', href: '//pagead2.googlesyndication.com' },
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
{ rel: 'author', type: 'text/plain', href: '/humans.txt' }
],
script: [
/*
{
body: true,
async: 'async',
type: 'text/javascript',
src: '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'
},
{
body: true,
type: 'text/javascript',
innerHTML: `
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: 'ca-pub-4710915636313788',
enable_page_level_ads: false
});`
}
*/
],
noscript: [
{ innerHTML: 'This website requires JavaScript.' }
],
__dangerouslyDisableSanitizers: ['script']
},
manifest: {
name: 'Surmon.me',
short_name: 'Surmon',
theme_color: '#0088f5',
display: 'standalone',
background_color: '#eee',
description: htmlSlogan,
lang: htmlLang
},
icon: {
iconSrc: '/static/icon.png',
sizes: [16, 120, 144, 152, 192, 384, 512]
},
modules: [
'@nuxtjs/pwa',
'@nuxtjs/axios',
],
router: {
middleware: ['change-page-col'],
linkActiveClass: 'link-active',
scrollBehavior(to, from, savedPosition) {
return { x: 0, y: 0 }
},
extendRoutes(routes) {}
},
css: [
'swiper/dist/css/swiper.css',
'highlight.js/styles/ocean.css',
{ src: '~assets/sass/app.scss', lang: 'sass' }
]
}