forked from rancher/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnuxt.config.js
287 lines (242 loc) · 7.03 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import fs from 'fs';
import path from 'path';
import { trimWhitespaceSsr as trimWhitespace } from './plugins/trim-whitespace';
import { directiveSsr as t } from './plugins/i18n';
import { STANDARD } from './config/private-label';
require('dotenv').config();
const version = process.env.VERSION ||
process.env.DRONE_TAG ||
process.env.DRONE_VERSION ||
require('./package.json').version;
const dev = (process.env.NODE_ENV !== 'production');
const pl = process.env.PL || STANDARD;
const commit = process.env.COMMIT || 'head';
const commitDate = process.env.COMMIT_DATE || '';
const commitBranch = process.env.COMMIT_BRANCH || '';
let api = process.env.API || 'http://localhost:8989';
if ( !api.startsWith('http') ) {
api = `https://${ api }`;
}
let routerBasePath = '/';
let resourceBase = '';
let outputDir = 'dist';
if ( typeof process.env.ROUTER_BASE !== 'undefined' ) {
routerBasePath = process.env.ROUTER_BASE;
}
if ( typeof process.env.RESOURCE_BASE !== 'undefined' ) {
resourceBase = process.env.RESOURCE_BASE;
}
if ( typeof process.env.OUTPUT_DIR !== 'undefined' ) {
outputDir = process.env.OUTPUT_DIR;
}
if ( resourceBase && !resourceBase.endsWith('/') ) {
resourceBase += '/';
}
console.log(`Build: ${ dev ? 'Development' : 'Production' }`); // eslint-disable-line no-console
if ( resourceBase ) {
console.log(`Resource Base URL: ${ resourceBase }`); // eslint-disable-line no-console
}
if ( routerBasePath !== '/' ) {
console.log(`Router Base Path: ${ routerBasePath }`); // eslint-disable-line no-console
}
if ( pl !== STANDARD ) {
console.log(`PL: ${ pl }`); // eslint-disable-line no-console
}
console.log(`API: ${ api }`); // eslint-disable-line no-console
module.exports = {
dev,
// Configuration visible to the client, https://nuxtjs.org/api/configuration-env
env: {
commit,
commitDate,
commitBranch,
version,
dev,
pl,
},
buildDir: dev ? '.nuxt' : '.nuxt-prod',
buildModules: [
'@nuxtjs/style-resources',
],
styleResources: {
// only import functions, mixins, or variables, NEVER import full styles https://github.com/nuxt-community/style-resources-module#warning
scss: [
'~assets/styles/base/_variables.scss',
'~assets/styles/base/_functions.scss',
'~assets/styles/base/_mixins.scss',
],
},
// mode: 'spa', --- Use --spa CLI flag, or ?spa query param.
loading: '~/components/nav/GlobalLoading.vue',
// Axios: https://axios.nuxtjs.org/options
axios: {
https: true,
proxy: true,
retry: { retries: 0 },
// debug: true
},
router: {
base: routerBasePath,
middleware: ['i18n'],
},
build: {
publicPath: resourceBase,
extend(config, { isClient, isDev }) {
config.devtool = isClient ? 'source-map' : 'inline-source-map';
if ( resourceBase ) {
config.output.publicPath = resourceBase;
}
config.module.rules.push({
test: /\.ya?ml$/i,
loader: 'js-yaml-loader',
options: { name: '[path][name].[ext]' },
});
// Run ESLint on save
if (isDev && isClient) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
});
}
},
// extractCSS: true,
cssSourceMap: true,
babel: {
presets({ isServer }) {
return [
[
require.resolve('@nuxt/babel-preset-app'),
{
buildTarget: isServer ? 'server' : 'client',
corejs: { version: 3 }
}
]
];
},
plugins: ['@babel/plugin-transform-modules-commonjs'],
}
},
render: {
bundleRenderer: {
directives: {
trimWhitespace,
t,
}
}
},
modern: true,
generate: { dir: outputDir },
// Global CSS
css: [
'@/assets/styles/app.scss'
],
head: {
title: process.env.npm_package_name || '',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{
hid: 'description',
name: 'description',
content: process.env.npm_package_description || ''
}
],
link: [{
rel: 'icon',
type: 'image/x-icon',
href: `${ resourceBase || '/' }favicon.png`
}]
},
// Nuxt modules
modules: [
'@nuxtjs/proxy',
'@nuxtjs/axios',
'@nuxtjs/eslint-module',
'cookie-universal-nuxt',
'portal-vue/nuxt',
'~/plugins/steve/rehydrate-all',
],
// Vue plugins
plugins: [
// Third-party
'~/plugins/axios',
'~/plugins/tooltip',
'~/plugins/vue-clipboard2',
'~/plugins/v-select',
'~/plugins/transitions',
{ src: '~plugins/vue-js-modal' },
{ src: '~/plugins/js-yaml', ssr: false },
{ src: '~/plugins/resize', ssr: false },
{ src: '~/plugins/shortkey', ssr: false },
// First-party
'~/plugins/i18n',
'~/plugins/global-formatters',
'~/plugins/trim-whitespace',
{ src: '~/plugins/extend-router' },
{ src: '~/plugins/lookup', ssr: false },
{ src: '~/plugins/nuxt-client-init', ssr: false },
],
// Proxy: https://github.com/nuxt-community/proxy-module#options
proxy: {
'/k8s': proxyWsOpts(api), // Straight to a remote cluster (/k8s/clusters/<id>/)
'/api': proxyWsOpts(api), // Managment k8s API
'/apis': proxyWsOpts(api), // Managment k8s API
'/v1': proxyWsOpts(api), // Management Steve API
'/v3': proxyWsOpts(api), // Rancher API
'/v3-public': proxyOpts(api), // Rancher Unauthed API
'/api-ui': proxyOpts(api), // Browser API UI
},
// Nuxt server
server: {
https: (dev ? {
key: fs.readFileSync(path.resolve(__dirname, 'server/server.key')),
cert: fs.readFileSync(path.resolve(__dirname, 'server/server.crt'))
} : null),
port: (dev ? 8005 : 80),
host: '0.0.0.0',
},
// Server middleware
serverMiddleware: [
'~/server/no-ssr'
],
// Eslint module options
eslint: { cache: '.eslintcache' },
};
function proxyOpts(target) {
return {
target,
secure: !dev,
onProxyReq,
onProxyReqWs,
onError
};
}
function proxyWsOpts(target) {
return {
...proxyOpts(target),
ws: true,
changeOrigin: true,
};
}
function onProxyReq(proxyReq, req) {
proxyReq.setHeader('x-api-host', req.headers['host']);
proxyReq.setHeader('x-forwarded-proto', 'https');
// console.log(proxyReq.getHeaders());
}
function onProxyReqWs(proxyReq, req, socket, options, head) {
req.headers.origin = options.target.href;
proxyReq.setHeader('origin', options.target.href);
proxyReq.setHeader('x-api-host', req.headers['host']);
proxyReq.setHeader('x-forwarded-proto', 'https');
// console.log(proxyReq.getHeaders());
socket.on('error', (err) => {
console.error('Proxy WS Error:', err); // eslint-disable-line no-console
});
}
function onError(err, req, res) {
res.statusCode = 500;
console.error('Proxy Error:', err); // eslint-disable-line no-console
res.write(JSON.stringify(err));
}