Skip to content

Commit f29d062

Browse files
committed
chore: update vite config for chunk splitting
1 parent 7ae1196 commit f29d062

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

docker/latest/patch/vite.config.ts

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ import { nodePolyfills } from 'vite-plugin-node-polyfills'
1111
import { VitePluginRadar } from 'vite-plugin-radar'
1212
import vueDevTools from 'vite-plugin-vue-devtools'
1313

14-
// https://vitejs.dev/config/
1514
export default defineConfig({
16-
base: `/`, // 基本路径, 建议以绝对路径跟随访问目录
17-
define: {
18-
process,
19-
},
20-
envPrefix: [`VITE_`, `CF_`], // 允许 VITE_ 和 CF_ 前缀的变量
15+
base: `/`,
16+
define: { process },
17+
envPrefix: [`VITE_`, `CF_`],
2118
plugins: [
2219
vue(),
2320
UnoCSS(),
@@ -30,43 +27,45 @@ export default defineConfig({
3027
},
3128
}),
3229
VitePluginRadar({
33-
analytics: {
34-
id: `G-7NZL3PZ0NK`,
35-
},
36-
}),
37-
process.env.ANALYZE === `true` && visualizer({
38-
emitFile: true,
39-
filename: `stats.html`,
30+
analytics: { id: `G-7NZL3PZ0NK` },
4031
}),
32+
process.env.ANALYZE === `true`
33+
&& visualizer({ emitFile: true, filename: `stats.html` }),
4134
AutoImport({
42-
imports: [
43-
`vue`,
44-
`pinia`,
45-
`@vueuse/core`,
46-
],
47-
dirs: [
48-
`./src/stores`,
49-
`./src/utils/toast`,
50-
],
35+
imports: [`vue`, `pinia`, `@vueuse/core`],
36+
dirs: [`./src/stores`, `./src/utils/toast`],
5137
}),
5238
Components({
5339
resolvers: [],
5440
}),
5541
],
5642
resolve: {
57-
alias: {
58-
'@': path.resolve(__dirname, `./src`),
59-
},
60-
},
61-
css: {
62-
devSourcemap: true,
43+
alias: { '@': path.resolve(__dirname, `./src`) },
6344
},
45+
css: { devSourcemap: true },
6446
build: {
6547
rollupOptions: {
6648
output: {
6749
chunkFileNames: `static/js/md-[name]-[hash].js`,
6850
entryFileNames: `static/js/md-[name]-[hash].js`,
6951
assetFileNames: `static/[ext]/md-[name]-[hash].[ext]`,
52+
manualChunks(id) {
53+
if (id.includes(`node_modules`)) {
54+
if (id.includes(`katex`))
55+
return `katex`
56+
if (id.includes(`mermaid`))
57+
return `mermaid`
58+
if (id.includes(`cytoscape`))
59+
return `cytoscape`
60+
if (id.includes(`highlight.js`))
61+
return `hljs`
62+
const pkg = id
63+
.split(`node_modules/`)[1]
64+
.split(`/`)[0]
65+
.replace(`@`, `npm_`)
66+
return `vendor_${pkg}`
67+
}
68+
},
7069
},
7170
},
7271
},

0 commit comments

Comments
 (0)