|
2 | 2 |
|
3 | 3 | - 20170a5 refactor: preload built `format` use `esm` by default |
4 | 4 |
|
| 5 | +#### Migration to v0.28.0 |
| 6 | + |
| 7 | +- **No break changes**. Just need to define `"type": "module"` in package.json for supports `esm` :) |
| 8 | +- **By the way**. Recommend using the `vite-plugin-electron/simple` API. It is simpler, and the main difference is its adaptation to `preload` scripts. |
| 9 | +- **electron@28** Preload scripts [👉 limitations](https://github.com/electron/electron/blob/v30.0.0-nightly.20240104/docs/tutorial/esm.md#preload-scripts). |
| 10 | + |
| 11 | +#### Preload scripts |
| 12 | + |
| 13 | +In most cases, use `cjs` format |
| 14 | + |
| 15 | +```log |
| 16 | +`require()` can usable matrix |
| 17 | +
|
| 18 | +@see - https://github.com/electron/electron/blob/v30.0.0-nightly.20240104/docs/tutorial/esm.md#preload-scripts |
| 19 | +┏———————————————————————————————————┳——————————┳———————————┓ |
| 20 | +│ webPreferences: { } │ import │ require │ |
| 21 | +┠———————————————————————————————————╂——————————╂———————————┨ |
| 22 | +│ nodeIntegration: false(undefined) │ ✘ │ ✔ │ |
| 23 | +┠———————————————————————————————————╂——————————╂———————————┨ |
| 24 | +│ nodeIntegration: true │ ✔ │ ✔ │ |
| 25 | +┠———————————————————————————————————╂——————————╂———————————┨ |
| 26 | +│ sandbox: true(undefined) │ ✘ │ ✔ │ |
| 27 | +┠———————————————————————————————————╂——————————╂———————————┨ |
| 28 | +│ sandbox: false │ ✔ │ ✘ │ |
| 29 | +┠———————————————————————————————————╂——————————╂———————————┨ |
| 30 | +│ nodeIntegration: false │ ✘ │ ✔ │ |
| 31 | +│ sandbox: true │ │ │ |
| 32 | +┠———————————————————————————————————╂——————————╂———————————┨ |
| 33 | +│ nodeIntegration: false │ ✔ │ ✘ │ |
| 34 | +│ sandbox: false │ │ │ |
| 35 | +┠———————————————————————————————————╂——————————╂———————————┨ |
| 36 | +│ nodeIntegration: true │ ✘ │ ✔ │ |
| 37 | +│ sandbox: true │ │ │ |
| 38 | +┠———————————————————————————————————╂——————————╂———————————┨ |
| 39 | +│ nodeIntegration: true │ ✔ │ ✔ │ |
| 40 | +│ sandbox: false │ │ │ |
| 41 | +┗———————————————————————————————————┸——————————┸———————————┛ |
| 42 | +- import(✘): SyntaxError: Cannot use import statement outside a module |
| 43 | +- require(✘): ReferenceError: require is not defined in ES module scope, you can use import instead |
| 44 | +``` |
| 45 | + |
| 46 | +#### Built format |
| 47 | + |
| 48 | +This is just the default behavior, and you can modify them at any time through custom config in the `vite.config.js` |
| 49 | + |
| 50 | +```log |
| 51 | +{ "type": "module" } |
| 52 | +┏————————————————————┳——————————┳———————————┓ |
| 53 | +│ built │ format │ suffix │ |
| 54 | +┠————————————————————╂——————————╂———————————┨ |
| 55 | +│ main process │ esm │ .js │ |
| 56 | +┠————————————————————╂——————————╂———————————┨ |
| 57 | +│ preload scripts │ cjs │ .mjs │ diff |
| 58 | +┠————————————————————╂——————————╂———————————┨ |
| 59 | +│ renderer process │ - │ .js │ |
| 60 | +┗————————————————————┸——————————┸———————————┛ |
| 61 | +
|
| 62 | +{ "type": "commonjs" } - default |
| 63 | +┏————————————————————┳——————————┳———————————┓ |
| 64 | +│ built │ format │ suffix │ |
| 65 | +┠————————————————————╂——————————╂———————————┨ |
| 66 | +│ main process │ cjs │ .js │ |
| 67 | +┠————————————————————╂——————————╂———————————┨ |
| 68 | +│ preload scripts │ cjs │ .js │ diff |
| 69 | +┠————————————————————╂——————————╂———————————┨ |
| 70 | +│ renderer process │ - │ .js │ |
| 71 | +┗————————————————————┸——————————┸———————————┛ |
| 72 | +``` |
| 73 | + |
5 | 74 | ## 0.28.0-beta.3 (2024-01-05) |
6 | 75 |
|
7 | 76 | - d7c0a91 feat: preload built `format` adapt to `esm` |
|
12 | 81 |
|
13 | 82 | #### Migration to v0.28.0-beta.2 |
14 | 83 |
|
15 | | -- **No break changes**. Just need to define `"type": "module"` in package.json for supports `esm` :) |
16 | | -- **By the way**. Recommend using the `vite-plugin-electron/simple` API. It is simpler, and the main difference is its adaptation to `preload` scripts. |
17 | | -- **electron@28** Preload scripts [👉 limitations](https://github.com/electron/electron/blob/v30.0.0-nightly.20231218/docs/tutorial/esm.md#preload-scripts). |
| 84 | +- ~~**No break changes**. Just need to define `"type": "module"` in package.json for supports `esm` :)~~ |
| 85 | +- ~~**By the way**. Recommend using the `vite-plugin-electron/simple` API. It is simpler, and the main difference is its adaptation to `preload` scripts.~~ |
| 86 | +- ~~**electron@28** Preload scripts [👉 limitations](https://github.com/electron/electron/blob/v30.0.0-nightly.20231218/docs/tutorial/esm.md#preload-scripts).~~ |
18 | 87 |
|
19 | 88 | ## 0.28.0-beta.1 (2023-12-30) |
20 | 89 |
|
|
0 commit comments