|
| 1 | +import path from 'node:path' |
| 2 | +import process from 'node:process' |
| 3 | + |
| 4 | +import vue from '@vitejs/plugin-vue' |
| 5 | +import { visualizer } from 'rollup-plugin-visualizer' |
| 6 | +import UnoCSS from 'unocss/vite' |
| 7 | +import AutoImport from 'unplugin-auto-import/vite' |
| 8 | +import Components from 'unplugin-vue-components/vite' |
| 9 | +import { defineConfig } from 'vite' |
| 10 | +import { nodePolyfills } from 'vite-plugin-node-polyfills' |
| 11 | +import { VitePluginRadar } from 'vite-plugin-radar' |
| 12 | +import vueDevTools from 'vite-plugin-vue-devtools' |
| 13 | + |
| 14 | +export default defineConfig({ |
| 15 | + base: `/`, |
| 16 | + define: { process }, |
| 17 | + envPrefix: [`VITE_`, `CF_`], |
| 18 | + plugins: [ |
| 19 | + vue(), |
| 20 | + UnoCSS(), |
| 21 | + vueDevTools(), |
| 22 | + nodePolyfills({ |
| 23 | + include: [`path`, `util`, `timers`, `stream`, `fs`], |
| 24 | + overrides: { |
| 25 | + // Since `fs` is not supported in browsers, we can use the `memfs` package to polyfill it. |
| 26 | + // fs: 'memfs', |
| 27 | + }, |
| 28 | + }), |
| 29 | + VitePluginRadar({ |
| 30 | + analytics: { id: `G-7NZL3PZ0NK` }, |
| 31 | + }), |
| 32 | + process.env.ANALYZE === `true` |
| 33 | + && visualizer({ emitFile: true, filename: `stats.html` }), |
| 34 | + AutoImport({ |
| 35 | + imports: [`vue`, `pinia`, `@vueuse/core`], |
| 36 | + dirs: [`./src/stores`, `./src/utils/toast`], |
| 37 | + }), |
| 38 | + Components({ |
| 39 | + resolvers: [], |
| 40 | + }), |
| 41 | + ], |
| 42 | + resolve: { |
| 43 | + alias: { '@': path.resolve(__dirname, `./src`) }, |
| 44 | + }, |
| 45 | + css: { devSourcemap: true }, |
| 46 | + build: { |
| 47 | + rollupOptions: { |
| 48 | + output: { |
| 49 | + chunkFileNames: `static/js/md-[name]-[hash].js`, |
| 50 | + entryFileNames: `static/js/md-[name]-[hash].js`, |
| 51 | + 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 | + }, |
| 69 | + }, |
| 70 | + }, |
| 71 | + }, |
| 72 | +}) |
0 commit comments