|
1 |
| -import fs from 'fs' |
2 |
| -import path from 'path' |
3 |
| -import { UserConfig } from 'vite' |
| 1 | +import { defineConfig } from 'vite' |
4 | 2 | import prefresh from '@prefresh/vite'
|
5 |
| -import windicss from 'vite-plugin-windicss' |
| 3 | +import { createConfig } from '../scripts/utils' |
6 | 4 |
|
7 |
| -const pkg = require('../package.json') |
8 |
| - |
9 |
| -function getPrismLanguages() { |
10 |
| - const files = fs.readdirSync('node_modules/prismjs/components') |
11 |
| - return files |
12 |
| - .filter((file) => file.endsWith('.min.js')) |
13 |
| - .map((file) => { |
14 |
| - const [, name] = /\-([^\.]+)/.exec(file)! |
15 |
| - return name |
16 |
| - }) |
17 |
| -} |
18 |
| - |
19 |
| -const config: UserConfig = { |
20 |
| - define: { |
21 |
| - DOCUP_VERSION: JSON.stringify(pkg.version), |
22 |
| - PRISM_VERSION: JSON.stringify(require('prismjs/package').version), |
23 |
| - PRISM_LANGUAGES: JSON.stringify(getPrismLanguages()), |
24 |
| - }, |
25 |
| - esbuild: { |
26 |
| - jsxFactory: 'h', |
27 |
| - jsxFragment: 'Fragment', |
28 |
| - }, |
29 |
| - resolve: { |
30 |
| - alias: { |
31 |
| - renderer: |
32 |
| - process.env.NODE_ENV === 'fre' |
33 |
| - ? path.resolve('src/renderer/fre.ts') |
34 |
| - : path.resolve('src/renderer/preact.ts'), |
35 |
| - }, |
36 |
| - }, |
37 |
| - plugins: [ |
38 |
| - prefresh(), |
39 |
| - windicss({ |
40 |
| - scan: { |
41 |
| - fileExtensions: ['tsx'], |
42 |
| - dirs: [path.resolve('src')], |
43 |
| - }, |
44 |
| - }), |
45 |
| - ], |
46 |
| - build: { |
47 |
| - target: ['es2020', 'safari14', 'chrome88'], |
48 |
| - minify: !process.env.DEBUG, |
49 |
| - polyfillDynamicImport: false, |
50 |
| - rollupOptions: { |
51 |
| - input: [ |
52 |
| - path.join(__dirname, 'main.ts'), |
53 |
| - path.join(__dirname, 'index.html'), |
54 |
| - ], |
55 |
| - preserveEntrySignatures: 'strict', |
56 |
| - output: { |
57 |
| - // Disable vendor chunk, make everything bundled in a single file |
58 |
| - manualChunks: undefined, |
59 |
| - }, |
60 |
| - }, |
61 |
| - }, |
62 |
| -} |
63 |
| - |
64 |
| -export default config |
| 5 | +export default defineConfig({ |
| 6 | + ...createConfig('preact', false), |
| 7 | + // @ts-expect-error |
| 8 | + plugins: [prefresh()], |
| 9 | +}) |
0 commit comments