-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnuxt.config.js
153 lines (150 loc) · 4.14 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
import {resolve} from 'path'
import {gql} from 'graphql-tag'
import useApolloClient, {init} from './apollo/'
const httpEndpoint = process.env.NODE_ENV === 'production' ? 'https://api.liaoliaojun.com' : 'http://dev.api.liaoliaojun.com:3000'
const graphqlEndpoint = process.env.NODE_ENV === 'production' ? 'https://api.liaoliaojun.com/graphql' : 'http://dev.api.liaoliaojun.com:3000/graphql'
// const httpEndpoint = 'https://api.liaoliaojun.com'
// const graphqlEndpoint = 'https://api.liaoliaojun.com/graphql'
export default {
ssr: true,
publicRuntimeConfig: {
httpEndpoint,
graphqlEndpoint,
},
head: {
title: '了了君的小站' || process.env.npm_package_name,
meta: [
{charset: 'utf-8'},
{'http-equiv': 'X-UA-Compatible', content: 'IE=Edge'},
{name: 'viewport', content: 'width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no'},
{hid: 'description', name: 'description', content: process.env.npm_package_description || ''},
],
link: [
{rel: 'icon', type: 'image/x-icon', href: '/favicon.ico'},
],
},
// render: {
// resourceHints: false, // 添加prefetch和preload,以加快初始化页面加载时间。如果有许多页面和路由,可禁用此项
// },
router: {
prefetchLinks: false, // 全局禁用所有链接上的预取
scrollBehavior: () => {
return new Promise((resolve) => {
// @ts-ignore
window.$nuxt.$once('triggerScroll', () => {
// 跳转时,滚动至顶部
if (document.querySelector('#app-container')) {
try {
// scroll to anchor by returning the selector
// @ts-ignore
document.querySelector('#app-container').scrollTop = 0
} catch (e) {
console.warn('Failed to save scroll position. Please add CSS.escape() polyfill (https://github.com/mathiasbynens/CSS.escape).')
}
}
resolve({x: 0, y: 0})
})
})
},
},
/*
** Customize the progress-bar color
*/
loading: {color: '#fff'},
/*
** Global CSS
*/
css: [
'~/assets/css/base.scss',
'~/assets/font/iconfont.css',
],
/*
** Plugins to load before mounting the App
*/
plugins: [
{src: '~/plugins/loading.ts'},
{src: '~/plugins/composition-api.ts'},
{src: '~/plugins/provide-apollo-client.ts'},
],
/*
** Nuxt.js dev-modules
*/
buildModules: [
'@nuxt/typescript-build',
// Doc: https://github.com/nuxt-community/nuxt-tailwindcss
'@nuxtjs/tailwindcss',
],
/*
** Nuxt.js modules
*/
modules: [
// '@nuxtjs/apollo',
'@nuxtjs/sitemap',
],
/*
** Build configuration
*/
build: {
postcss: {
plugins: {
tailwindcss: resolve(__dirname, './tailwind.config.js'),
autoprefixer: {},
},
},
babel: {
presets ({isServer}) {
return [
[
require.resolve('@nuxt/babel-preset-app'),
// require.resolve('@nuxt/babel-preset-app-edge'), // For nuxt-edge users
{
buildTarget: isServer ? 'server' : 'client',
corejs: {version: 3},
},
],
]
},
},
/*
** You can extend webpack config here
*/
extend () {
},
},
// apollo: {
// clientConfigs: {
// default: {
// httpEndpoint: 'https://api.liaoliaojun.com:3000/graphql',
// },
// },
// },
tailwindcss: {
configPath: resolve(__dirname, './tailwind.config.js'),
cssPath: '~/assets/css/tailwind.css',
},
server: {
host: '0.0.0.0',
port: 3001,
},
// 设置网站地图
sitemap: {
path: '/sitemap.xml',
gzip: true,
routes: async () => {
const query = gql`
query queryArticles {
result: articles {
# 文章id
article_id
}
}
`
init(graphqlEndpoint)
return await useApolloClient().defaultClient.query({
query,
}).then((res) => {
return (res.data.result || []).map((article) => `/article/${article.article_id}`)
}).catch((error) => console.log(`dynamic routes error: ${error}`))
},
},
}