Skip to content

Commit

Permalink
refactor(electron): bundle dependencies (#738)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocavue authored Jul 25, 2021
1 parent ae03049 commit 3e951c2
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

import { defineConfig } from "vite"

// https://vitejs.dev/config/
Expand Down
8 changes: 5 additions & 3 deletions packages/electron-main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "tsc --build --watch ./src/tsconfig.json",
"build": "tsc --build ./src/tsconfig.json"
"dev": "tsc --build ./src/tsconfig.json && vite build ./src --watch",
"build": "tsc --build ./src/tsconfig.json && vite build ./src"
},
"dependencies": {
"electron-log": "^4.4.0",
"electron-updater": "^4.3.9"
},
"devDependencies": {
"@rino.app/electron-types": "workspace:0.0.0",
"builtin-modules": "^3.2.0",
"electron": "13.1.7",
"typescript": "^4.3.5"
"typescript": "^4.3.5",
"vite": "^2.4.3"
}
}
2 changes: 1 addition & 1 deletion packages/electron-main/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { app, Menu } from "electron"
import { autoUpdater } from "electron-updater"

import { registerIpcInvokeHandlers } from "./api-main"
import { buildApplicationMenu } from "./application-menu"
Expand All @@ -13,7 +14,6 @@ async function setupAutoUpdate() {
await app.whenReady()
await new Promise((resolve) => setTimeout(resolve, 1000))
try {
const { autoUpdater } = await import("electron-updater")
autoUpdater.logger = logger
await autoUpdater.checkForUpdatesAndNotify()
} catch (e) {
Expand Down
6 changes: 3 additions & 3 deletions packages/electron-main/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"noEmit": false,
"outDir": "../dist",
"composite": true,
"noEmit": false,
"emitDeclarationOnly": true,
"outDir": "./.cache/typescript",
},
"include": [
"./",
Expand Down
23 changes: 23 additions & 0 deletions packages/electron-main/src/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// @ts-check

import builtinModules from "builtin-modules"
import { defineConfig } from "vite"

// https://vitejs.dev/config/
export default defineConfig((env) => ({
build: {
minify: "esbuild",
sourcemap: true,
chunkSizeWarningLimit: 2000,
outDir: "../dist",
emptyOutDir: true,

lib: {
entry: "./main.ts",
formats: ["cjs"],
},
rollupOptions: {
external: [...builtinModules, "electron", "fs/promises"],
},
},
}))
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

import reactRefresh from "@vitejs/plugin-react-refresh"
import { defineConfig } from "vite"

Expand Down
6 changes: 1 addition & 5 deletions packages/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@rino.app/electron",
"version": "0.0.0",
"private": true,
"main": "./build/electron-main/dist/main.js",
"main": "./build/electron-main/dist/electron-main.cjs.js",
"author": "ocavue",
"description": "A better way to write Markdown",
"scripts": {
Expand All @@ -16,9 +16,5 @@
"electron-builder": "^22.11.7",
"electron-notarize": "^1.0.0",
"wait-on": "^6.0.0"
},
"dependencies": {
"electron-log": "^4.4.0",
"electron-updater": "^4.3.9"
}
}
14 changes: 9 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3e951c2

Please sign in to comment.