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

[Maybe A Bug] Variable names in VSCode debugger doesn't map with source variable names. #637

Open
4 tasks done
panghal0 opened this issue Oct 16, 2024 · 0 comments
Open
4 tasks done

Comments

@panghal0
Copy link

panghal0 commented Oct 16, 2024

Describe the bug

I am not sure if it's an issue with electron-vite or something else. Putting it here with hopes to get some directions at least.

Issue:
When debugging the main process with VSCode the sourcemaps works fine and the breakpoints in the source file are hit. But the variable names in the Variables panel doesn't match with those in source files, rather they are mapped with build files (in dist/main/).

Variable names not matching with the source files (Breakpoints works though)
image

Variable names matching with the generated build files
image

Not able to figure out where exactly is the issue.

Launch.json

{
	"version": "0.2.0",
	"configurations": [
		{
			"name": "Debug Main Process",
			"type": "node",
			"request": "launch",
			"cwd": "${workspaceRoot}",
			"trace": true,
			"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-vite",
			"windows": {
				"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-vite.cmd"
			},
			"runtimeArgs": ["--sourcemap", "--outDir=dist", "--config=${workspaceRoot}/electron.vite.config.mjs"],
			"env": {
				"REMOTE_DEBUGGING_PORT": "9222",
				"NODE_ENV": "development"
			}
		},
		{
			"name": "Debug Renderer Process",
			"port": 9222,
			"request": "attach",
			"type": "chrome",
			"webRoot": "${workspaceFolder}/src/",
			"timeout": 60000,
			"presentation": {
				"hidden": true
			}
		}
	],
	"compounds": [
		{
			"name": "Debug All",
			"configurations": ["Debug Main Process", "Debug Renderer Process"],
			"presentation": {
				"order": 1
			}
		}
	]
}

electron.vite.config.mjs

import { defineConfig, externalizeDepsPlugin, bytecodePlugin, splitVendorChunkPlugin } from 'electron-vite';
import { resolve } from 'path';
import react from '@vitejs/plugin-react';
import replace from '@rollup/plugin-replace';

import obfuscatorPlugin from 'vite-plugin-javascript-obfuscator';
import obfuscatorOptions from './obfuscator.options';

let skipCodeProtection = process.env.CODE_PROTECTION;
skipCodeProtection = !!skipCodeProtection && skipCodeProtection === 'SKIP';

const nodeEnv = process.env.NODE_ENV;

export default defineConfig({
	emptyOutDir: true,
	main: {
		plugins: [externalizeDepsPlugin(), skipCodeProtection ? null : bytecodePlugin({ removeBundleJS: false })],
		build: {
			minify: true,
			outDir: 'dist/main',
			sourcemap: true,
			rollupOptions: {
				input: {
					index: resolve(__dirname, 'electron/main.js')
				}
			}
		}
	},
	preload: {
		plugins: [externalizeDepsPlugin(), skipCodeProtection ? null : bytecodePlugin({ removeBundleJS: true })],
		build: {
			minify: true,
			outDir: 'dist/preload',
			rollupOptions: {
				input: {
					preload: resolve(__dirname, 'electron/preloads/preload.js')
				}
			}
		}
	},
	renderer: {
		root: nodeEnv === 'development' ? './src' : '.',
		server: { fs: { strict: false } },
		publicDir: nodeEnv === 'development' ? './assets' : './src/assets',
		build: {
			outDir: 'dist/renderer',
			target: 'chrome120',
			rollupOptions: {
				input: {
					index: resolve('./src/index.html')
				}
			}
		},
		plugins: [
			splitVendorChunkPlugin(),
			react(),
			skipCodeProtection
				? null
				: obfuscatorPlugin({
						include: ['src/**/*.js'],
						exclude: [/node_modules/],
						apply: 'build',
						options: obfuscatorOptions
				  })
		],
		optimizeDeps: {
			force: true,
			esbuildOptions: {
				loader: {
					'.js': 'jsx'
				}
			}
		},
		resolve: {
			alias: {
				'@renderer': resolve('src')
			}
		}
	}
});

Thanks in advance.

Electron-Vite Version

2.3.0

Electron Version

30.3.1

Vite Version

5.4.8

Validations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant