Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViteでビルドをしながらVSCodeでDebugを行えるようにする #1221

Merged
merged 13 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .vscode/launch.template.json
Original file line number Diff line number Diff line change
@@ -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 Render Process",
yamachu marked this conversation as resolved.
Show resolved Hide resolved
// NOTE: background.tsで指定しているremote-debugging-port
"port": 13579,
"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": [
"<node_internals>/**"
],
"type": "node"
},
{
"name": "Attach by Process ID",
// .bin viteを指定するとElectronのMain Processのデバッグが可能
"processId": "${command:PickProcess}",
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
],
"compounds": [
{
"name": "Launch Electron Main/Render",
"configurations": ["Attach to Render Process", "Launch Electron Main Process via NPM"],
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
"stopAll": true
}
]
}
4 changes: 4 additions & 0 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ type SingleInstanceLockData = {
const isDevelopment = import.meta.env.DEV;
const isTest = import.meta.env.MODE === "test";

if (isDevelopment) {
app.commandLine.appendSwitch("remote-debugging-port", "13579");
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
}

let suffix = "";
if (isTest) {
suffix = "-test";
Expand Down
3 changes: 3 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import checker from "vite-plugin-checker";
rmSync(path.resolve(__dirname, "dist"), { recursive: true, force: true });

const isElectron = process.env.VITE_IS_ELECTRON === "true";
const isDevelopment = process.env.NODE_ENV === "development";
sevenc-nanashi marked this conversation as resolved.
Show resolved Hide resolved

const config: UserConfig = {
root: path.resolve(__dirname, "src"),
build: {
outDir: path.resolve(__dirname, "dist"),
chunkSizeWarningLimit: 10000,
sourcemap: isDevelopment ? "inline" : false,
},
publicDir: path.resolve(__dirname, "public"),
css: {
Expand Down Expand Up @@ -66,6 +68,7 @@ const config: UserConfig = {
plugins: [tsconfigPaths({ root: __dirname })],
build: {
outDir: path.resolve(__dirname, "dist"),
sourcemap: isDevelopment ? "inline" : false,
},
},
}),
Expand Down