-
-
Notifications
You must be signed in to change notification settings - Fork 261
/
dev-mode.js
67 lines (55 loc) · 1.59 KB
/
dev-mode.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {build, createServer} from 'vite';
import path from 'path';
/**
* This script is designed to run multiple packages of your application in a special development mode.
* To do this, you need to follow a few steps:
*/
/**
* 1. We create a few flags to let everyone know that we are in development mode.
*/
const mode = 'development';
process.env.NODE_ENV = mode;
process.env.MODE = mode;
/**
* 2. We create a development server for the renderer. It is assumed that the renderer exists and is located in the “renderer” package.
* This server should be started first because other packages depend on its settings.
*/
/**
* @type {import('vite').ViteDevServer}
*/
const rendererWatchServer = await createServer({
mode,
root: path.resolve('packages/renderer'),
});
await rendererWatchServer.listen();
/**
* 3. We are creating a simple provider plugin.
* Its only purpose is to provide access to the renderer dev-server to all other build processes.
*/
/** @type {import('vite').Plugin} */
const rendererWatchServerProvider = {
name: '@vite-electron-builder/renderer-watch-server-provider',
api: {
provideRendererWatchServer() {
return rendererWatchServer;
},
},
};
/**
* 4. Start building all other packages.
* For each of them, we add a plugin provider so that each package can implement its own hot update mechanism.
*/
/** @type {string[]} */
const packagesToStart = [
'packages/preload',
'packages/main',
];
for (const pkg of packagesToStart) {
await build({
mode,
root: path.resolve(pkg),
plugins: [
rendererWatchServerProvider,
],
});
}