-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnuxt.config.ts
175 lines (150 loc) · 3.8 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
import path, { join } from 'path'
import { Configuration } from '@nuxt/types'
import Sass from 'sass'
import posts from './posts/posts.json'
import address from 'address'
import defaultGateway from 'default-gateway'
const IS_PRODUCTION = process.env.NODE_ENV === 'production'
/**
* 获取本地 IP
*
* https://github.com/vuejs/vue-cli/blob/eda18b05424c8c3e6862a7a5e2e15b7513bebbe4/packages/%40vue/cli-service/lib/util/prepareURLs.js#L37
*/
let localIp = 'localhost'
try {
// This can only return an IPv4 address
const result = defaultGateway.v4.sync()
const lanUrlForConfig = address.ip(result && result.interface)
if (lanUrlForConfig) {
// Check if the address is a private ip
// https://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces
if (
/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(
lanUrlForConfig,
)
) {
localIp = lanUrlForConfig
}
}
} catch (_e) {
// ignored
}
const config: Configuration = {
// Disable server-side rendering (https://go.nuxtjs.dev/ssr-mode)
ssr: false,
// Target (https://go.nuxtjs.dev/config-target)
target: 'static',
// Auto import components (https://go.nuxtjs.dev/config-components)
components: true,
/*
** Headers of the page
*/
head: {
titleTemplate: (title) => {
return title ? `${title} - 田写` : '田写'
},
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: '田勇的博客。技术、生活及其它……' },
],
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
},
/*
** Customize the progress-bar color
*/
loading: { color: '#ff9b36' },
/*
** Global CSS
*/
css: ['~/assets/scss/app.scss'],
/*
** Plugins to load before mounting the App
*/
plugins: [
{
src: '~/plugins/app-service.ts',
ssr: false,
},
],
/*
** Nuxt.js modules
*/
modules: [
// Doc: https://axios.nuxtjs.org/usage
'@nuxtjs/axios',
// https://github.com/nuxt-community/svg-sprite-module
'@nuxtjs/svg-sprite',
'@nuxt/content',
],
buildModules: [
'@nuxt/typescript-build',
// https://go.nuxtjs.dev/tailwindcss
// '@nuxtjs/tailwindcss',
'@nuxtjs/dotenv',
],
/*
** Axios module configuration
*/
axios: {
// See https://github.com/nuxt-community/axios-module#options
},
content: {
liveEdit: true,
markdown: {
remarkPlugins: [
'remark-emoji',
// 'remark-admonitions',
'remark-slug',
'remark-autolink-headings',
'remark-external-links',
'remark-footnotes',
],
prism: {
theme: 'prism-themes/themes/prism-material-oceanic.css',
},
},
},
svgSprite: {
// https://github.com/nuxt-community/svg-sprite-module
// manipulate module options
},
/*
** Build configuration
*/
build: {
parallel: false, // 这个设置为 false,因为 extractCSS 为true 时冲突
// 生产环境下才提取,开发环境下提取可能导致修改样式后无法热替换(hmr)
extractCSS: process.env.NODE_ENV === 'production',
transpile: ['color'],
loaders: {
scss: {
implementation: Sass,
},
},
postcss: {
plugins: {
'postcss-import': {},
'postcss-url': {},
tailwindcss: {},
autoprefixer: {},
...(IS_PRODUCTION ? { cssnano: {} } : {}),
},
},
},
// TODO:
// generate: {
// routes: ['404'].concat(posts.map(post => `/posts/${post.slugifiedFilename}`)),
// },
router: {
mode: 'hash',
},
server: {
host: process.env.DEV_SERVER_HOST || localIp,
port: 3000,
},
env: {
GIT_TOKEN: process.env.GIT_TOKEN,
},
}
export default config