generated from tomo0613/ts-project-starter
-
Notifications
You must be signed in to change notification settings - Fork 4
/
vite.buildConfig.ts
52 lines (46 loc) · 1.69 KB
/
vite.buildConfig.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
import { defineConfig } from 'vite';
const INDEX = 'index';
export default defineConfig({
base: './',
publicDir: 'assets',
esbuild: {
jsxInject: 'import React from "react"',
},
build: {
rollupOptions: {
output: {
entryFileNames: '[name][hash].js',
assetFileNames: 'static/[name]-[hash][extname]',
chunkFileNames({ name, facadeModuleId }) {
if (!facadeModuleId && name.startsWith('vendor_')) {
return `vendor/${name.replace('vendor_', '')}-[hash].js`;
}
if (!facadeModuleId && name === 'vendor') {
return 'vendor/[name]-[hash].js';
}
if (name === INDEX && facadeModuleId) {
const folderName = facadeModuleId.replace(`/${INDEX}.js`, '').split('/').pop();
return `modules/${folderName}-[hash].js`;
}
return 'modules/[name]-[hash].js';
},
manualChunks(id) {
if (!id.includes('node_modules')) {
return undefined;
}
if (id.includes('react')) {
return 'vendor_react';
}
if (id.includes('cannon')) {
return 'vendor_cannon';
}
if (id.includes('three')) {
return 'vendor_three';
}
return 'vendor';
},
},
},
chunkSizeWarningLimit: 660,
},
});