Skip to content

Commit

Permalink
Merge pull request #48 from electron-vite/v0.13.9
Browse files Browse the repository at this point in the history
V0.13.9
  • Loading branch information
caoxiemeihao authored Mar 26, 2023
2 parents fd69328 + 6b4a24a commit 3d54e6f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.13.9 (2023-03-26)

- 6ff0897 fix: use bare-path instead absolute-path

## 0.13.8 (2023-03-26)

- 9490072 docs: v0.13.8
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-renderer",
"version": "0.13.8",
"version": "0.13.9",
"description": "Support use Node.js API in Electron-Renderer",
"main": "index.js",
"types": "types",
Expand Down
22 changes: 12 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import cjsShim from './cjs-shim'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const builtins = builtinModules.filter(m => !m.startsWith('_')); builtins.push(...builtins.map(m => `node:${m}`))
const electronBuiltins = ['electron', ...builtins]
// Must be use absolute path for `pnnpm` monorepo - `shamefully-hoist=true`
const BUILTINS_PATH = path.join(__dirname, 'builtins')
const RESOLVE_PATH = path.join(__dirname, '.resolve')

export interface RendererOptions {
/**
Expand Down Expand Up @@ -87,7 +84,12 @@ export default function renderer(options: RendererOptions = {}): VitePlugin[] {
.filter(m => !m.startsWith('node:'))
.map<Alias>(m => ({
find: new RegExp(`^(node:)?${m}$`),
replacement: path.join(BUILTINS_PATH, m),

// Must be use absolute path for `pnnpm` monorepo - `shamefully-hoist=true`, but it will cause pre-bundle errors. 🤔
// `error: The entry point "electron" cannot be marked as external`
// replacement: path.join(__dirname, 'builtins', m),

replacement: `vite-plugin-electron-renderer/builtins/${m}`,
}))

// Why is the builtin modules loaded by modifying `resolve.alias` instead of using the plugin `resolveId` + `load` hooks?
Expand Down Expand Up @@ -160,16 +162,16 @@ async function buildResolve(options: RendererOptions) {

if (!snippets) continue

const resolvePath = path.join(RESOLVE_PATH, name)
aliases.push({
find: name,
replacement: resolvePath,
})

const resolvePath = path.join(__dirname, '.resolve', name)
if (!/* reuse cache */fs.existsSync(resolvePath)) {
ensureDir(path.dirname(resolvePath))
fs.writeFileSync(resolvePath + '.mjs', snippets)
}

aliases.push({
find: name,
replacement: `vite-plugin-electron-renderer/.resolve/${name}`,
})
}

return aliases
Expand Down

0 comments on commit 3d54e6f

Please sign in to comment.