Compare commits

...

4 Commits

Author SHA1 Message Date
alex8088
db1128089a release: v2.0.0-beta.1 2023-12-14 21:19:04 +08:00
alex8088
0b265442a1 feat: env variables prefixed with VITE_ will be shared in main process and renderer 2023-12-14 21:14:49 +08:00
alex8088
7b27e684d6 perf: dev error message 2023-12-14 20:49:22 +08:00
alex8088
dbd7b0137b fix: externalizeDepsPlugin not work 2023-12-14 20:46:00 +08:00
4 changed files with 26 additions and 12 deletions

View File

@ -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

View File

@ -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",

View File

@ -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_']
}
},
{

View File

@ -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))
})
}