Skip to content

Commit

Permalink
Merge pull request #15 from daltonmenezes/chore/source-code-protection
Browse files Browse the repository at this point in the history
chore: update electron vite for source code protection support
  • Loading branch information
daltonmenezes authored Sep 21, 2022
2 parents 6029a23 + c71d457 commit 3ad60ea
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 8 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

# <img src="./docs/images/bullet.svg" width="14" /> 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,
},
})
```

# <img src="./docs/images/bullet.svg" width="19" /> Documents
<table >
<tr>
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand All @@ -68,4 +68,4 @@
"eslintIgnore": [
"dist"
]
}
}
19 changes: 14 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 3ad60ea

Please sign in to comment.