-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
51 lines (48 loc) · 1.55 KB
/
vite.config.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
import { resolve } from 'path'
import { existsSync, readFileSync } from 'fs'
import { defineConfig, Plugin } from 'vite'
import ssr from 'vite-plugin-ssr/plugin'
/**
* TEMP: Temporary plugin to remove an entry if not used.
* TODO: Take some time to make PR to avoid this dirty plugin ???
* @see: `isUsingClientRouter` from node/plugin/plugins/extractExportNamesPlugin.ts
* @see: is `config.vitePluginSsr.prerender` accessible from node/plugin/plugins/buildConfig.ts
*/
const _defaultClientPagePath = resolve(__dirname, 'renderer/_default.page.client.tsx')
const noUnusedEntryPlugin = (): Plugin => {
let usePrerender: boolean = false
let useClientRouting: boolean = (
existsSync(_defaultClientPagePath) &&
/export const clientRouting(\s.*|)=(\s.*|)true/gm.test(readFileSync(_defaultClientPagePath).toString())
)
return {
name: 'no-unused-entry-plugin',
apply: 'build',
enforce: 'post',
config(config) {
// @ts-ignore
usePrerender = config.vitePluginSsr.prerender !== false
},
options(options) {
if (!useClientRouting) delete options.input['entry-client-routing']
if (usePrerender) delete options.input['entry-server-routing']
}
}
}
export default defineConfig({
clearScreen: false,
plugins: [
ssr({ prerender: true }),
noUnusedEntryPlugin()
],
build: {
rollupOptions: {
input: {
main: resolve(__dirname, 'src/main.ts')
}
}
},
esbuild: {
jsxInject: `import React from 'react'`
}
})