|
1 | 1 | import { defineConfig, type UserConfig } from 'vite';
|
2 | 2 | import { fileURLToPath } from 'url';
|
3 | 3 | import checker from 'vite-plugin-checker';
|
| 4 | +import fs from 'node:fs'; |
4 | 5 | import Vue from '@vitejs/plugin-vue';
|
5 | 6 |
|
| 7 | +const pkg = require('./package.json'); |
| 8 | + |
6 | 9 | // https://vitejs.dev/config/
|
7 |
| -const config: UserConfig = { |
8 |
| - base: './', |
9 |
| - // Resolver |
10 |
| - resolve: { |
11 |
| - // https://vitejs.dev/config/#resolve-alias |
12 |
| - alias: { |
13 |
| - '@': fileURLToPath(new URL('./src', import.meta.url)), |
14 |
| - }, |
15 |
| - }, |
16 |
| - // https://vitejs.dev/config/#server-options |
17 |
| - server: { |
18 |
| - fs: { |
19 |
| - // Allow serving files from one level up to the project root |
20 |
| - allow: ['..'], |
| 10 | +export default defineConfig(async ({ mode, command }): Promise<UserConfig> => { |
| 11 | + const config: UserConfig = { |
| 12 | + // https://vitejs.dev/config/shared-options.html#base |
| 13 | + base: './', |
| 14 | + // Resolver |
| 15 | + resolve: { |
| 16 | + // https://vitejs.dev/config/shared-options.html#resolve-alias |
| 17 | + alias: { |
| 18 | + '@': fileURLToPath(new URL('./src', import.meta.url)), |
| 19 | + }, |
21 | 20 | },
|
22 |
| - }, |
23 |
| - plugins: [ |
24 |
| - Vue(), |
25 |
| - // vite-plugin-checker |
26 |
| - // https://github.com/fi3ework/vite-plugin-checker |
27 |
| - checker({ |
28 |
| - typescript: true, |
29 |
| - vueTsc: true, |
30 |
| - eslint: { |
31 |
| - lintCommand: 'eslint', // for example, lint .ts & .tsx |
| 21 | + // https://vitejs.dev/config/#server-options |
| 22 | + server: { |
| 23 | + fs: { |
| 24 | + // Allow serving files from one level up to the project root |
| 25 | + allow: ['..'], |
32 | 26 | },
|
33 |
| - }), |
34 |
| - ], |
35 |
| - // Build Options |
36 |
| - // https://vitejs.dev/config/#build-options |
37 |
| - build: { |
38 |
| - outDir: 'docs', |
39 |
| - rollupOptions: { |
40 |
| - output: { |
41 |
| - manualChunks: { |
42 |
| - vue: ['vue', 'vue-demi'], |
43 |
| - lodash: ['lodash'], |
44 |
| - codemirror: [ |
45 |
| - 'codemirror', |
46 |
| - '@codemirror/autocomplete', |
47 |
| - '@codemirror/commands', |
48 |
| - '@codemirror/language', |
49 |
| - '@codemirror/lint', |
50 |
| - '@codemirror/search', |
51 |
| - '@codemirror/state', |
52 |
| - '@codemirror/view', |
53 |
| - // Add the following as needed. |
54 |
| - '@codemirror/lang-html', |
55 |
| - '@codemirror/lang-javascript', |
56 |
| - '@codemirror/lang-markdown', |
57 |
| - ], |
58 |
| - eslint: ['eslint-linter-browserify'], |
| 27 | + }, |
| 28 | + plugins: [ |
| 29 | + Vue(), |
| 30 | + // vite-plugin-checker |
| 31 | + // https://github.com/fi3ework/vite-plugin-checker |
| 32 | + checker({ |
| 33 | + typescript: true, |
| 34 | + vueTsc: true, |
| 35 | + eslint: { |
| 36 | + lintCommand: 'eslint', |
| 37 | + }, |
| 38 | + }), |
| 39 | + ], |
| 40 | + optimizeDeps: { |
| 41 | + exclude: ['vue-demi'], |
| 42 | + }, |
| 43 | + // Build Options |
| 44 | + // https://vitejs.dev/config/#build-options |
| 45 | + build: { |
| 46 | + outDir: 'docs', |
| 47 | + rollupOptions: { |
| 48 | + output: { |
| 49 | + manualChunks: { |
| 50 | + vue: ['vue', 'vue-demi'], |
| 51 | + lodash: ['lodash'], |
| 52 | + codemirror: [ |
| 53 | + 'codemirror', |
| 54 | + '@codemirror/autocomplete', |
| 55 | + '@codemirror/commands', |
| 56 | + '@codemirror/language', |
| 57 | + '@codemirror/lint', |
| 58 | + '@codemirror/search', |
| 59 | + '@codemirror/state', |
| 60 | + '@codemirror/view', |
| 61 | + // Add the following as needed. |
| 62 | + '@codemirror/lang-html', |
| 63 | + '@codemirror/lang-javascript', |
| 64 | + '@codemirror/lang-markdown', |
| 65 | + ], |
| 66 | + eslint: ['eslint-linter-browserify'], |
| 67 | + }, |
59 | 68 | },
|
60 | 69 | },
|
| 70 | + // Minify option |
| 71 | + target: 'esnext', |
| 72 | + minify: 'esbuild', |
| 73 | + }, |
| 74 | + esbuild: { |
| 75 | + // drop: command === 'serve' ? [] : ['console'], |
61 | 76 | },
|
62 |
| - target: 'esnext', |
63 |
| - }, |
| 77 | + }; |
| 78 | + |
| 79 | + // Write meta data. |
| 80 | + fs.writeFileSync( |
| 81 | + fileURLToPath(new URL('./src/Meta.ts', import.meta.url)), |
| 82 | + `import type MetaInterface from '@/interfaces/MetaInterface'; |
| 83 | +
|
| 84 | +// This file is auto-generated by the build system. |
| 85 | +const meta: MetaInterface = { |
| 86 | + version: '${pkg.version}', |
| 87 | + date: '${new Date().toISOString()}', |
64 | 88 | };
|
| 89 | +export default meta; |
| 90 | +` |
| 91 | + ); |
65 | 92 |
|
66 |
| -// Export vite config |
67 |
| -export default defineConfig(config); |
| 93 | + // Export vite config |
| 94 | + return config; |
| 95 | +}); |
0 commit comments