| 23 | const d = debug('electron-forge:plugin:vite'); |
| 24 | |
| 25 | export default class VitePlugin extends PluginBase<VitePluginConfig> { |
| 26 | private static alreadyStarted = false; |
| 27 | |
| 28 | public name = 'vite'; |
| 29 | |
| 30 | private isProd = false; |
| 31 | |
| 32 | /** |
| 33 | * Path to the root of the Electron app |
| 34 | */ |
| 35 | private projectDir!: string; |
| 36 | |
| 37 | /** |
| 38 | * Path where Vite output is generated. Usually `${projectDir}/.vite` |
| 39 | */ |
| 40 | private baseDir!: string; |
| 41 | |
| 42 | private configGeneratorCache!: ViteConfigGenerator; |
| 43 | |
| 44 | private watchers: vite.Rollup.RollupWatcher[] = []; |
| 45 | |
| 46 | private servers: vite.ViteDevServer[] = []; |
| 47 | |
| 48 | // Matches the format of the default Vite logger |
| 49 | private timeFormatter = new Intl.DateTimeFormat(undefined, { |
| 50 | hour: 'numeric', |
| 51 | minute: 'numeric', |
| 52 | second: 'numeric', |
| 53 | }); |
| 54 | |
| 55 | init = (dir: string): void => { |
| 56 | this.setDirectories(dir); |
| 57 | |
| 58 | d('hooking process events'); |
| 59 | process.on('exit', (_code) => { |
| 60 | this.exitHandler({ cleanup: true }); |
| 61 | }); |
| 62 | process.on('SIGINT' as NodeJS.Signals, (_signal) => { |
| 63 | this.exitHandler({ exit: true }); |
| 64 | }); |
| 65 | }; |
| 66 | |
| 67 | public setDirectories(dir: string): void { |
| 68 | this.projectDir = dir; |
| 69 | this.baseDir = path.join(dir, '.vite'); |
| 70 | } |
| 71 | |
| 72 | private get configGenerator(): ViteConfigGenerator { |
| 73 | return (this.configGeneratorCache ??= new ViteConfigGenerator( |
| 74 | this.config, |
| 75 | this.projectDir, |
| 76 | this.isProd, |
| 77 | )); |
| 78 | } |
| 79 | |
| 80 | getHooks = (): ForgeMultiHookMap => { |
| 81 | return { |
| 82 | preStart: [ |
nothing calls this directly
no test coverage detected