diff --git a/README.md b/README.md index 066436b..316b743 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ - 😎 Preload (context bridge) already configured - 🙀 IPC communication example included - 🔮 GitHub Action releases with `Windows`, `Mac` and `Linux` binaries + - 🔒 Source Code Protection support - 🍪 Absolute paths support - **Technologies**: - 🔋 Electron @@ -100,6 +101,41 @@ In this process, the action will be triggered and the previous command will open https://user-images.githubusercontent.com/1149845/156939675-5ea0c510-ddd3-4de7-b293-87d3697bd1a8.mp4 +# Source Code Protection +> This process is done via [v8 bytecode compilation](https://nodejs.org/api/vm.html#vm_script_createcacheddata), to get more knowledge about it, please, [check the Electron Vite docs](https://evite.netlify.app/guide/source-code-protection.html). + +Use the `bytecodePlugin` from `electron-vite` to enable it in the **electron.vite.config.ts**: + +```ts +import { defineConfig, bytecodePlugin } from 'electron-vite' + +export default defineConfig({ + main: { + plugins: [tsconfigPaths, bytecodePlugin()] + }, + + preload: { + // Note: you will get the following warning using bytecodePlugin in the preload script in production build: "The vm module of Node.js is deprecated in the renderer process and will be removed", is up to you to keep bytecodePlugin here. Also, keep following the Electron Vite docs for more updates about this plugin! + plugins: [tsconfigPaths, bytecodePlugin()] + }, + + renderer: { + // ... + } +}) +``` +Also, `sandbox` should be `false` in `webPreferences` for the windows you are using a preload script like: +```ts +const window = createWindow({ + id: 'main', + + webPreferences: { + preload: join(__dirname, '../preload/index.js'), + sandbox: false, + }, +}) +``` + # Documents diff --git a/package.json b/package.json index c6b480b..9e436b3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "displayName": "My Awesome Electron App", "name": "my-awesome-electron-app", "description": "Your awesome app description", - "version": "2.0.1", + "version": "2.0.2", "main": "./node_modules/.dev/main/index.js", "resources": "src/resources", "author": { @@ -43,7 +43,7 @@ "electron": "^20.1.4", "electron-builder": "^23.3.3", "electron-react-devtools": "^0.5.3", - "electron-vite": "^1.0.8", + "electron-vite": "^1.0.9", "eslint": "^8.22.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-node": "^11.1.0", @@ -68,4 +68,4 @@ "eslintIgnore": [ "dist" ] -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index 845a288..25925d0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -27,7 +27,7 @@ resolved "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.19.1.tgz" integrity sha512-72a9ghR0gnESIa7jBN53U32FOVCEoztyIlKaNoU05zRhEecduGK9L9c3ww7Mp06JiR+0ls0GBPFJQwwtjn9ksg== -"@babel/core@^7.18.13": +"@babel/core@^7.18.13", "@babel/core@^7.19.1": version "7.19.1" resolved "https://registry.npmjs.org/@babel/core/-/core-7.19.1.tgz" integrity sha512-1H8VgqXme4UXCRv7/Wa1bq7RVymKOzC7znjyFM8KiEzwFqcKUKYNoQef4GhdklgNvoBXyW4gYhuBNCM5o1zImw== @@ -179,6 +179,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.18.6" +"@babel/plugin-transform-arrow-functions@^7.18.6": + version "7.18.6" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.18.6.tgz#19063fcf8771ec7b31d742339dac62433d0611fe" + integrity sha512-9S9X9RUefzrsHZmKMbDXxweEH+YlE8JJEuat9FdvW9Qh1cw7W64jELCtWNkPBPX5En45uy28KGvA/AySqUh8CQ== + dependencies: + "@babel/helper-plugin-utils" "^7.18.6" + "@babel/plugin-transform-react-jsx-development@^7.18.6": version "7.18.6" resolved "https://registry.npmjs.org/@babel/plugin-transform-react-jsx-development/-/plugin-transform-react-jsx-development-7.18.6.tgz" @@ -1812,11 +1819,13 @@ electron-to-chromium@^1.4.251: resolved "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.254.tgz" integrity sha512-Sh/7YsHqQYkA6ZHuHMy24e6TE4eX6KZVsZb9E/DvU1nQRIrH4BflO/4k+83tfdYvDl+MObvlqHPRICzEdC9c6Q== -electron-vite@^1.0.8: - version "1.0.8" - resolved "https://registry.npmjs.org/electron-vite/-/electron-vite-1.0.8.tgz" - integrity sha512-NxvXf88lUcUbULAq31QBRht/nMUqkXGIIJLmZKytmGMC2ZZf1NxLWsMG9N0/sg1xG+HxHZ1eeuEI1j74U5Vsrw== +electron-vite@^1.0.9: + version "1.0.9" + resolved "https://registry.yarnpkg.com/electron-vite/-/electron-vite-1.0.9.tgz#4656823a56472777dc584b920e1e8729ea3bdce5" + integrity sha512-UB+l0xlJNTMVOD3wdK+8Tqv/S0eHiiFKPaA72DrHtEOvOQdjC6YGjTW7d29Yen+VJLtP3Ccef6TG07uZjOihsA== dependencies: + "@babel/core" "^7.19.1" + "@babel/plugin-transform-arrow-functions" "^7.18.6" cac "^6.7.12" esbuild "^0.14.54" picocolors "^1.0.0"