-
Notifications
You must be signed in to change notification settings - Fork 12
/
vite.config.js
59 lines (54 loc) · 1.88 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
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import svgLoader from 'vite-svg-loader';
import path from 'path';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import analyze from 'rollup-plugin-analyzer';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { visualizer } from 'rollup-plugin-visualizer';
svgLoader({
svgoConfig: {
multipass: true,
},
});
const injectNpmVersion = () => {
return {
name: 'inject-npm-version',
config: () => ({ define: { 'import.meta.env.VERSION': JSON.stringify(process.env.npm_package_version) } }),
};
};
const htmlPlugin = () => {
return {
name: 'html-transform',
transformIndexHtml(html, ctx) {
if (!ctx?.chunk?.dynamicImports)
return html;
// Prefetch some scripts that we'll load and can take some time to load. Can help, can not help, depending.
const preloadScripts = ctx.chunk.dynamicImports.filter(x => x.indexOf('Dispatch') !== -1 || x.indexOf('three') !== -1)
return html.replace(
'</script>',
'</script>\n ' + preloadScripts.map(x => `<link rel="prefetch" as="script" crossorigin href="/${x}">`).join('\n '),
)
},
}
}
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
assetsInclude: ['**/*.exr', '**/*.mp3'],
build: {
target: 'es2020',
sourcemap: true,
minify: false,
},
test: {
globals: true,
environment: 'jsdom',
},
// Uncomment to see details on what's going with rollup
plugins: [vue(), svgLoader(), injectNpmVersion(), htmlPlugin()],//, analyze({ showExports: true }), visualizer({ template: 'treemap', sourcemap: true })],
}));