mirror of
https://github.com/alex8088/electron-vite.git
synced 2026-07-14 02:41:08 +08:00
Compare commits
4 Commits
73f2562172
...
db1128089a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db1128089a | ||
|
|
0b265442a1 | ||
|
|
7b27e684d6 | ||
|
|
dbd7b0137b |
@ -1,3 +1,9 @@
|
||||
### v2.0.0-beta.1 (_2023-12-14_)
|
||||
|
||||
- feat: env variables prefixed with VITE\_ will be shared in main process and renderer
|
||||
- fix: externalizeDepPlugin not work
|
||||
- perf: dev error message
|
||||
|
||||
### v2.0.0-beta.0 (_2023-12-13_)
|
||||
|
||||
- feat: bump minimum node version to 18
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "electron-vite",
|
||||
"version": "2.0.0-beta.0",
|
||||
"version": "2.0.0-beta.1",
|
||||
"description": "Electron build tooling based on Vite",
|
||||
"type": "module",
|
||||
"main": "dist/index.cjs",
|
||||
|
||||
@ -117,7 +117,7 @@ export function electronMainVitePlugin(options?: ElectronPluginOptions): Plugin[
|
||||
config.define = config.define || {}
|
||||
config.define = { ...processEnvDefine(), ...config.define }
|
||||
|
||||
config.envPrefix = config.envPrefix || 'MAIN_VITE_'
|
||||
config.envPrefix = config.envPrefix || ['MAIN_VITE_', 'VITE_']
|
||||
|
||||
config.publicDir = config.publicDir || 'resources'
|
||||
// do not copy public dir
|
||||
@ -127,6 +127,7 @@ export function electronMainVitePlugin(options?: ElectronPluginOptions): Plugin[
|
||||
// enable ssr build
|
||||
config.build.ssr = true
|
||||
config.build.ssrEmitAssets = true
|
||||
config.ssr = { ...config.ssr, ...{ noExternal: true } }
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -261,7 +262,7 @@ export function electronPreloadVitePlugin(options?: ElectronPluginOptions): Plug
|
||||
config.define = config.define || {}
|
||||
config.define = { ...processEnvDefine(), ...config.define }
|
||||
|
||||
config.envPrefix = config.envPrefix || 'PRELOAD_VITE_'
|
||||
config.envPrefix = config.envPrefix || ['PRELOAD_VITE_', 'VITE_']
|
||||
|
||||
config.publicDir = config.publicDir || 'resources'
|
||||
// do not copy public dir
|
||||
@ -271,6 +272,7 @@ export function electronPreloadVitePlugin(options?: ElectronPluginOptions): Plug
|
||||
// enable ssr build
|
||||
config.build.ssr = true
|
||||
config.build.ssrEmitAssets = true
|
||||
config.ssr = { ...config.ssr, ...{ noExternal: true } }
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -374,7 +376,7 @@ export function electronRendererVitePlugin(options?: ElectronPluginOptions): Plu
|
||||
|
||||
config.envDir = config.envDir || path.resolve(root)
|
||||
|
||||
config.envPrefix = config.envPrefix || 'RENDERER_VITE_'
|
||||
config.envPrefix = config.envPrefix || ['RENDERER_VITE_', 'VITE_']
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -24,6 +24,10 @@ export async function createServer(
|
||||
let server: ViteDevServer | undefined
|
||||
let ps: ChildProcess | undefined
|
||||
|
||||
const errorHook = (e): void => {
|
||||
logger.error(`${colors.bgRed(colors.white(' ERROR '))} ${colors.red(e.message)}`)
|
||||
}
|
||||
|
||||
const mainViteConfig = config.config?.main
|
||||
if (mainViteConfig && !options.rendererOnly) {
|
||||
const watchHook = (): void => {
|
||||
@ -40,7 +44,7 @@ export async function createServer(
|
||||
}
|
||||
}
|
||||
|
||||
await doBuild(mainViteConfig, watchHook)
|
||||
await doBuild(mainViteConfig, watchHook, errorHook)
|
||||
|
||||
logger.info(colors.green(`\nbuild the electron main process successfully`))
|
||||
}
|
||||
@ -59,7 +63,7 @@ export async function createServer(
|
||||
}
|
||||
}
|
||||
|
||||
await doBuild(preloadViteConfig, watchHook)
|
||||
await doBuild(preloadViteConfig, watchHook, errorHook)
|
||||
|
||||
logger.info(colors.green(`\nbuild the electron preload files successfully`))
|
||||
}
|
||||
@ -108,7 +112,7 @@ export async function createServer(
|
||||
|
||||
type UserConfig = ViteConfig & { configFile?: string | false }
|
||||
|
||||
async function doBuild(config: UserConfig, watchHook: () => void): Promise<void> {
|
||||
async function doBuild(config: UserConfig, watchHook: () => void, errorHook: (e: Error) => void): Promise<void> {
|
||||
return new Promise(resolve => {
|
||||
if (config.build?.watch) {
|
||||
let firstBundle = true
|
||||
@ -131,10 +135,12 @@ async function doBuild(config: UserConfig, watchHook: () => void): Promise<void>
|
||||
})
|
||||
}
|
||||
|
||||
viteBuild(config).then(() => {
|
||||
if (!config.build?.watch) {
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
viteBuild(config)
|
||||
.then(() => {
|
||||
if (!config.build?.watch) {
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
.catch(e => errorHook(e))
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user