Skip to content

Commit 15c4efe

Browse files
authoredDec 14, 2022
Merge pull request #119 from electron-vite/v0.11.0-beta1
V0.11.0 beta1
2 parents 1571a62 + d9c3343 commit 15c4efe

File tree

5 files changed

+52
-50
lines changed

5 files changed

+52
-50
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export interface Configuration {
8484
startup: (argv?: string[]) => Promise<void>
8585
/** Reload Electron-Renderer */
8686
reload: () => void
87-
}) => void
87+
}) => void | Promise<void>
8888
}
8989
```
9090

‎src/build.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import {
66
} from './config'
77

88
/** Work on the `vite build` command */
9-
export async function build(config: Configuration | Configuration[]) {
10-
const configArray = Array.isArray(config) ? config : [config]
11-
12-
for (const config of configArray) {
13-
const inlineConfig = withExternalBuiltins(resolveViteConfig(config))
14-
await viteBuild(inlineConfig)
15-
}
9+
export function build(config: Configuration) {
10+
return viteBuild(withExternalBuiltins(resolveViteConfig(config)))
1611
}

‎src/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface Configuration {
2727
startup: (argv?: string[]) => Promise<void>
2828
/** Reload Electron-Renderer */
2929
reload: () => void
30-
}) => void
30+
}) => void | Promise<void>
3131
}
3232

3333
export function defineConfig(config: Configuration) {

‎src/index.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,26 @@ import { bootstrap } from './serve'
44
import type { Configuration } from './config'
55

66
// public
7-
export { type Configuration, defineConfig, resolveViteConfig, withExternalBuiltins } from './config'
7+
export {
8+
type Configuration,
9+
defineConfig,
10+
resolveViteConfig,
11+
withExternalBuiltins,
12+
} from './config'
813
export { build }
914

1015
export default function electron(config: Configuration | Configuration[]): Plugin[] {
16+
const configArray = Array.isArray(config) ? config : [config]
17+
1118
return [
1219
{
1320
name: 'vite-plugin-electron',
1421
apply: 'serve',
1522
configureServer(server) {
1623
server.httpServer?.once('listening', () => {
17-
bootstrap(config, server)
24+
for (const config of configArray) {
25+
bootstrap(config, server)
26+
}
1827
})
1928
server.httpServer?.once('close', () => {
2029
if (process.electronApp) {
@@ -32,7 +41,9 @@ export default function electron(config: Configuration | Configuration[]): Plugi
3241
config.base ??= './'
3342
},
3443
async closeBundle() {
35-
await build(config)
44+
for (const config of configArray) {
45+
await build(config)
46+
}
3647
}
3748
},
3849
]

‎src/serve.ts

+34-38
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,44 @@ import {
1313
} from './config'
1414

1515
/** Work on the `vite serve` command */
16-
export async function bootstrap(config: Configuration | Configuration[], server: ViteDevServer) {
16+
export function bootstrap(config: Configuration, server: ViteDevServer) {
1717
Object.assign(process.env, {
1818
VITE_DEV_SERVER_URL: resolveServerUrl(server)
1919
})
2020

21-
const configArray = Array.isArray(config) ? config : [config]
22-
23-
for (const config of configArray) {
24-
const inlineConfig = withExternalBuiltins(resolveViteConfig(config))
25-
await viteBuild(mergeConfig(
26-
{
27-
mode: server.config.mode,
28-
build: {
29-
watch: {},
30-
},
31-
plugins: [{
32-
name: ':startup',
33-
closeBundle() {
34-
if (config.onstart) {
35-
config.onstart.call(this, {
36-
startup,
37-
reload() {
38-
server.ws.send({ type: 'full-reload' })
39-
},
40-
})
41-
} else {
42-
// TODO: 2022-10-12 Rollup can't accurately distinguish a file with multiple entries
43-
if (false/* path.parse(filename).name.endsWith('reload') */) {
44-
// Bundle filename that ends with `reload` will trigger the Electron-Renderer process to reload,
45-
// instead of restarting the entire Electron App.
46-
// e.g.
47-
// dist/electron/preload.ts
48-
// dist/electron/foo.reload.js
21+
const inlineConfig = withExternalBuiltins(resolveViteConfig(config))
22+
return viteBuild(mergeConfig(
23+
<UserConfig>{
24+
mode: server.config.mode,
25+
build: {
26+
watch: {},
27+
},
28+
plugins: [{
29+
name: ':startup',
30+
closeBundle() {
31+
if (config.onstart) {
32+
config.onstart.call(this, {
33+
startup,
34+
reload() {
4935
server.ws.send({ type: 'full-reload' })
50-
} else {
51-
startup()
52-
}
36+
},
37+
})
38+
} else {
39+
// TODO: 2022-10-12 Rollup can't accurately distinguish a file with multiple entries
40+
if (false/* path.parse(filename).name.endsWith('reload') */) {
41+
// Bundle filename that ends with `reload` will trigger the Electron-Renderer process to reload,
42+
// instead of restarting the entire Electron App.
43+
// e.g.
44+
// dist/electron/preload.ts
45+
// dist/electron/foo.reload.js
46+
server.ws.send({ type: 'full-reload' })
47+
} else {
48+
startup()
5349
}
54-
},
55-
}],
56-
} as UserConfig,
57-
inlineConfig,
58-
))
59-
}
50+
}
51+
},
52+
}],
53+
},
54+
inlineConfig,
55+
))
6056
}

0 commit comments

Comments
 (0)
Please sign in to comment.