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

V0.28.0 #198

Merged
merged 2 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.28.0 (2024-01-07)

- 20170a5 refactor: preload built `format` use `esm` by default

## 0.28.0-beta.3 (2024-01-05)

- d7c0a91 feat: preload built `format` adapt to `esm`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-electron",
"version": "0.28.0-beta.3",
"version": "0.28.0",
"description": "Electron 🔗 Vite",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
14 changes: 7 additions & 7 deletions src/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ export default async function electronSimple(options: ElectronSimpleOptions): Pr
// `rollupOptions.input` has higher priority than `build.lib`.
// https://github.com/vitejs/vite/blob/v5.0.9/packages/vite/src/node/build.ts#L482
input,
// For use the Electron API - `import { contextBridge, ipcRenderer } from 'electron'`,
output: {
// For use the Electron API - `import { contextBridge, ipcRenderer } from 'electron'`,
// Note, however, that `preload.ts` should not be split. 🚧
format: esmodule ? 'esm' : 'cjs',
// In most cases, use `cjs` format.
// @see - https://github.com/electron/electron/blob/v30.0.0-nightly.20240104/docs/tutorial/esm.md#preload-scripts
// @see - https://github.com/electron-vite/vite-plugin-electron-preload/blob/v0.2.0/src/index.ts#L24-L47
format: 'cjs',

// Whether Node.js is enabled in the Main process or not, the Preload scripts supports loading `electron` module,
// so we need to build it in `cjs` format.
Expand All @@ -63,15 +65,13 @@ export default async function electronSimple(options: ElectronSimpleOptions): Pr
// // ↓↓↓↓ Build with `cjs` format ↓↓↓↓
// const { ipcRenderer } = require('electron')

// https://github.com/electron/electron/blob/v30.0.0-nightly.20231218/docs/tutorial/esm.md#preload-scripts
// At [email protected] the built-in modules still supports `cjs` | `require('electron')` | 2023-12-30

// Note, however, that `preload.ts` should not be split. 🚧
// When Rollup builds code in `cjs` format, it will automatically split the code into multiple chunks, and use `require()` to load them,
// and use `require()` to load other modules when `nodeIntegration: false` in the Main process Errors will occur.
// So we need to configure Rollup not to split the code when building to ensure that it works correctly with `nodeIntegration: false`.
inlineDynamicImports: true,

// https://github.com/vitejs/vite/blob/v5.0.9/packages/vite/src/node/build.ts#L608
// @see - https://github.com/vitejs/vite/blob/v5.0.9/packages/vite/src/node/build.ts#L608
entryFileNames: `[name].${esmodule ? 'mjs' : 'js'}`,
chunkFileNames: `[name].${esmodule ? 'mjs' : 'js'}`,
assetFileNames: '[name].[ext]',
Expand Down