diff --git a/.vscode/launch.template.json b/.vscode/launch.template.json new file mode 100644 index 0000000000..969c53d659 --- /dev/null +++ b/.vscode/launch.template.json @@ -0,0 +1,47 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Attach to Renderer Process", + // NOTE: background.tsで指定しているremote-debugging-port + "port": 9222, + "request": "attach", + "type": "chrome", + "webRoot": "${workspaceFolder}", + "timeout": 20000, // 20 * 1000 ms程度あればビルド時間は間に合うはず + }, + { + "name": "Launch Electron Main Process via NPM", + "request": "launch", + "runtimeArgs": [ + "run", + "electron:serve" + ], + "runtimeExecutable": "npm", + "skipFiles": [ + "/**" + ], + "type": "node" + }, + { + "name": "Attach by Process ID", + // .bin viteを指定するとElectronのMain Processのデバッグが可能 + "processId": "${command:PickProcess}", + "request": "attach", + "skipFiles": [ + "/**" + ], + "type": "node" + }, + ], + "compounds": [ + { + "name": "Launch Electron Main/Renderer", + "configurations": ["Attach to Renderer Process", "Launch Electron Main Process via NPM"], + "stopAll": true + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 9c2e5194a5..a264831244 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,12 @@ npx openapi-generator-cli generate \ npm run fmt ``` +## VS Code でのデバッグ実行 + +npm scripts の `serve` や `electron:serve` などの開発ビルド下では、ビルドに使用している vite で sourcemap を出力するため、ソースコードと出力されたコードの対応付けが行われます。 + +`.vscode/launch.template.json` をコピーして `.vscode/launch.json` を作成することで、開発ビルドを VS Code から実行し、デバッグを可能にするタスクが有効になります。 + ## ライセンス LGPL v3 と、ソースコードの公開が不要な別ライセンスのデュアルライセンスです。 diff --git a/src/background.ts b/src/background.ts index c4b996657a..608ce6d946 100644 --- a/src/background.ts +++ b/src/background.ts @@ -49,6 +49,10 @@ type SingleInstanceLockData = { const isDevelopment = import.meta.env.DEV; const isTest = import.meta.env.MODE === "test"; +if (isDevelopment) { + app.commandLine.appendSwitch("remote-debugging-port", "9222"); +} + let suffix = ""; if (isTest) { suffix = "-test"; diff --git a/vite.config.ts b/vite.config.ts index 7f47c9b5ed..18c2971ddc 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -7,7 +7,7 @@ import electron from "vite-plugin-electron"; import tsconfigPaths from "vite-tsconfig-paths"; import vue from "@vitejs/plugin-vue"; import checker from "vite-plugin-checker"; -import { defineConfig } from "vite"; +import { BuildOptions, defineConfig } from "vite"; import { quasar } from "@quasar/vite-plugin"; rmSync(path.resolve(__dirname, "dist"), { recursive: true, force: true }); @@ -15,11 +15,16 @@ rmSync(path.resolve(__dirname, "dist"), { recursive: true, force: true }); const isElectron = process.env.VITE_IS_ELECTRON === "true"; export default defineConfig((options) => { + const shouldEmitSourcemap = ["development", "test"].includes(options.mode); + const sourcemap: BuildOptions["sourcemap"] = shouldEmitSourcemap + ? "inline" + : false; return { root: path.resolve(__dirname, "src"), build: { outDir: path.resolve(__dirname, "dist"), chunkSizeWarningLimit: 10000, + sourcemap, }, publicDir: path.resolve(__dirname, "public"), css: { @@ -74,6 +79,7 @@ export default defineConfig((options) => { plugins: [tsconfigPaths({ root: __dirname })], build: { outDir: path.resolve(__dirname, "dist"), + sourcemap, }, }, }),