Skip to content

Commit 61f8682

Browse files
authored
Build: Migration to VIteJS (#83)
1 parent 3aaf095 commit 61f8682

35 files changed

+1668
-5953
lines changed

.stylelintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.stylelintrc.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

forge.config.ts

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { ForgeConfig } from '@electron-forge/shared-types';
2-
import { WebpackPlugin } from '@electron-forge/plugin-webpack';
32
import { MakerZIP } from '@electron-forge/maker-zip';
43
import { PublisherGithub } from '@electron-forge/publisher-github';
4+
import { VitePlugin } from '@electron-forge/plugin-vite';
5+
import { FusesPlugin } from '@electron-forge/plugin-fuses';
6+
import { FuseV1Options, FuseVersion } from '@electron/fuses';
57
import { config } from 'dotenv';
68

7-
import { mainConfig } from './webpack.main.config';
8-
import { rendererConfig } from './webpack.renderer.config';
99
import { version } from './package.json';
1010

1111
config();
@@ -15,12 +15,12 @@ const isDev = process.env.IS_DEV === 'true';
1515
const forgeConfig: ForgeConfig = {
1616
makers: [new MakerZIP({}, ['darwin'])],
1717
packagerConfig: {
18+
asar: true,
1819
appBundleId: 'app.devkitty',
1920
appCategoryType: 'public.app-category.developer-tools',
20-
appCopyright: 'Copyright © 2023 Devkitty',
21+
appCopyright: 'Copyright © 2024 Devkitty',
2122
appVersion: version,
2223
executableName: 'Devkitty',
23-
// extendInfo: './extend.plist',
2424
icon: './icons/icon',
2525
name: 'Devkitty',
2626
osxNotarize: !isDev
@@ -40,21 +40,37 @@ const forgeConfig: ForgeConfig = {
4040
overwrite: true
4141
},
4242
plugins: [
43-
new WebpackPlugin({
44-
mainConfig,
45-
renderer: {
46-
config: rendererConfig,
47-
entryPoints: [
48-
{
49-
html: './src/rendered/index.html',
50-
js: './src/rendered/index.tsx',
51-
name: 'main_window',
52-
preload: {
53-
js: './src/main/ipcs/preload.ts'
54-
}
55-
}
56-
]
57-
}
43+
new VitePlugin({
44+
// `build` can specify multiple entry builds, which can be Main process, Preload scripts, Worker process, etc.
45+
// If you are familiar with Vite configuration, it will look really familiar.
46+
build: [
47+
{
48+
config: 'vite.main.config.ts',
49+
// `entry` is just an alias for `build.lib.entry` in the corresponding file of `config`.
50+
entry: 'src/main/app.ts'
51+
},
52+
{
53+
config: 'vite.preload.config.ts',
54+
entry: 'src/main/ipcs/preload.ts'
55+
}
56+
],
57+
renderer: [
58+
{
59+
config: 'vite.renderer.config.ts',
60+
name: 'main_window'
61+
}
62+
]
63+
}),
64+
// Fuses are used to enable/disable various Electron functionality
65+
// at package time, before code signing the application
66+
new FusesPlugin({
67+
version: FuseVersion.V1,
68+
[FuseV1Options.RunAsNode]: false,
69+
[FuseV1Options.EnableCookieEncryption]: true,
70+
[FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
71+
[FuseV1Options.EnableNodeCliInspectArguments]: false,
72+
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
73+
[FuseV1Options.OnlyLoadAppFromAsar]: true
5874
})
5975
],
6076
publishers: [

forge.env.d.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export {}; // Make this a module
2+
3+
declare global {
4+
// This allows TypeScript to pick up the magic constants that's auto-generated by Forge's Vite
5+
// plugin that tells the Electron app where to look for the Vite-bundled app code (depending on
6+
// whether you're running in development or production).
7+
const MAIN_WINDOW_VITE_DEV_SERVER_URL: string;
8+
const MAIN_WINDOW_VITE_NAME: string;
9+
10+
namespace NodeJS {
11+
interface Process {
12+
// Used for hot reload after preload scripts.
13+
viteDevServers: Record<string, import('vite').ViteDevServer>;
14+
}
15+
}
16+
17+
type VitePluginConfig = ConstructorParameters<typeof import('@electron-forge/plugin-vite').VitePlugin>[0];
18+
19+
interface VitePluginRuntimeKeys {
20+
VITE_DEV_SERVER_URL: `${string}_VITE_DEV_SERVER_URL`;
21+
VITE_NAME: `${string}_VITE_NAME`;
22+
}
23+
}
24+
25+
declare module 'vite' {
26+
interface ConfigEnv<K extends keyof VitePluginConfig = keyof VitePluginConfig> {
27+
root: string;
28+
forgeConfig: VitePluginConfig;
29+
forgeConfigSelf: VitePluginConfig[K][number];
30+
}
31+
}

index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta
6+
name="viewport"
7+
content="width=device-width, initial-scale=1.0"
8+
/>
9+
<title>Devkitty</title>
10+
</head>
11+
<body>
12+
<div id="app" />
13+
<script
14+
type="module"
15+
src="/src/rendered/index.tsx"
16+
></script>
17+
</body>
18+
</html>

0 commit comments

Comments
 (0)