-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvite.config.js
96 lines (90 loc) · 2.57 KB
/
vite.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
/* eslint-disable import/no-extraneous-dependencies */
import { defineConfig } from 'vite';
import { HstVue } from '@histoire/plugin-vue';
import commonViteConfig from './build/commonViteConfig.js';
import getPluginProxies from './build/getPluginProxies.js';
import { determineHostFromArgv } from './build/determineHost.js';
const configMain = defineConfig(async ({ mode }) => {
const production = mode === 'production';
const https = false;
const port = production ? 4173 : 8080;
let proxy = {};
if (!production) {
const host = determineHostFromArgv(port, https);
proxy = await getPluginProxies(host, production);
proxy['/node_modules/@vcmap-cesium/engine/Build/Assets'] = {
target: host,
rewrite: (path) => path.replace(/Build/, 'Source'),
};
proxy['/node_modules/@vcmap-cesium/engine/Build/ThirdParty'] = {
target: host,
rewrite: (path) => path.replace(/Build/, 'Source'),
};
} else {
const pluginRegistryIndex = process.argv.indexOf('--plugin-registry');
if (pluginRegistryIndex > -1 && process.argv[pluginRegistryIndex + 1]) {
proxy['/plugins'] = {
target: process.argv[pluginRegistryIndex + 1],
rewrite: (path) => path.replace(/plugins/, 'map-plugin'),
};
}
}
const modules = [];
process.argv.forEach((arg, index, args) => {
if (arg === '--module' && index < args.length) {
modules.push(args[index + 1]);
}
});
if (modules.length) {
proxy['/app.config.json'] = {
target: 'vc.systems',
selfHandleResponse: true,
configure(server) {
server.on('proxyReq', (proxyRes, req, res) => {
res.write(JSON.stringify({ modules }));
res.end();
});
},
};
}
const config = {
...commonViteConfig,
server: {
https,
strictPort: true,
port,
proxy,
},
optimizeDeps: {
include: ['vuetify'],
},
histoire: {
plugins: [HstVue()],
setupFile: {
browser: './story/setup.js',
},
vite: {
base: process.env.HISTOIRE_DEPLOYMENT
? process.env.HISTOIRE_DEPLOYMENT
: './',
server: {
host: process.argv.includes('--host'),
},
},
},
};
if (process.env.NO_OPTIMIZED_CORE) {
config.optimizeDeps = {
exclude: ['@vcmap/core', 'ol'],
include: [
'@vcmap/core > fast-deep-equal',
'@vcmap/core > rbush-knn',
'@vcmap/core > rbush-knn > tinyqueue',
'@vcmap/core > pbf',
'@vcmap-cesium/engine',
],
};
}
return config;
});
export default configMain;