-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnuxt.config.js
More file actions
128 lines (121 loc) · 3.26 KB
/
nuxt.config.js
File metadata and controls
128 lines (121 loc) · 3.26 KB
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
import blogConfig from './blog.config'
const path = require('path')
// 资源路径前缀,生产环境使用cdn域名
const publicPath =
process.env.PATH_TYPE !== 'production' ? '/_nuxt/' : '/_nuxt/'
export default {
mode: 'universal', // 普遍的 —— 同构应用程序(服务端呈现 + 客户端路由导航)
env: {
PATH_TYPE: process.env.PATH_TYPE // 在项目代码中直接使用 process.env.PATH_TYPE 直接获取环境参数
},
vue: {
config: {
productionTip: false,
devtools: process.env.PATH_TYPE !== 'production'
}
},
router: {
base: blogConfig.baseUrl, // 项目访问路径
scrollBehavior(to, from, savedPosition) {
if (savedPosition) {
return savedPosition
} else {
return { x: 0, y: 0 }
}
}
},
// Global page headers: https://go.nuxtjs.dev/config-head
head: {
title: blogConfig.seo.title,
meta: [
{
name: 'description',
content: blogConfig.seo.description
},
{
name: 'keywords',
content: blogConfig.seo.keywords
}
]
},
loading: {
color: 'rgb(0, 197, 142)',
height: '3px'
},
// Global CSS: https://go.nuxtjs.dev/config-css
css: ['~/styles/reset.css', '~/styles/global.scss'],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [
{
src: '~/plugins/entry-plugin/main.js',
ssr: true
},
{
src: '~/plugins/i18n.js',
ssr: true
}
],
// Modules: https://go.nuxtjs.dev/config-modules
modules: ['@nuxtjs/axios'],
axios: {
proxy: true, // 表示开启代理
// prefix: '/api/chanel', // 表示给请求url加个前缀 /api
credentials: true // 表示跨域请求时是否需要使用凭证
},
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
publicPath: publicPath,
transpile: [/vant.*?less/],
babel: {
babelrc: false,
plugins: [
[
'lodash',
{
libraryName: 'lodash', // 配置lodash按需加载
libraryDirectory: '',
camel2DashComponentName: false
},
'lodash'
]
]
},
/*
** You can extend webpack config here
*/
// extend(config, ctx) {}
extend(config, { isClient }) {
// 为 客户端打包 进行扩展配置
if (isClient) {
config.externals = {}
// 非开发环境移除runtime打包
if (process.env.PATH_TYPE != 'development') {
config.externals.vue = 'Vue'
config.externals.vuex = 'Vuex'
config.externals['vue-router'] = 'VueRouter'
}
// 非生产环境开启 source-map
if (process.env.PATH_TYPE !== 'production') {
config.devtool = 'eval-source-map'
Object.assign(config.output, {
devtoolModuleFilenameTemplate: 'yanyue404://[resource-path]'
})
}
// 添加别名
config.resolve.alias['@'] = path.resolve(__dirname)
}
},
extractCSS: { allChunks: false },
analyze: true,
profile: false
},
render: {
resourceHints: false,
asyncScripts: true
},
proxy: ['https://api.github.com/search', 'https://api.github.com/repos'],
server: {
port: 9527,
host: '127.0.0.1'
}
}