-
-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(plugin-vite): move built-in vite config to template config file
- Loading branch information
1 parent
2d244f0
commit b4da787
Showing
15 changed files
with
289 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,11 @@ | ||
import { builtinModules } from 'node:module'; | ||
|
||
// eslint-disable-next-line node/no-unpublished-import | ||
import type { Plugin } from 'vite'; | ||
|
||
/** | ||
* `electron` and Node.js built-in modules should always be externalize. | ||
*/ | ||
export function externalBuiltins() { | ||
return <Plugin>{ | ||
name: '@electron-forge/plugin-vite:external-builtins', | ||
config(config) { | ||
const nativeModules = builtinModules.filter((e) => !e.startsWith('_')); | ||
const builtins = ['electron', ...nativeModules, ...nativeModules.map((m) => `node:${m}`)]; | ||
|
||
config.build ??= {}; | ||
config.build.rollupOptions ??= {}; | ||
|
||
let external = config.build.rollupOptions.external; | ||
if (Array.isArray(external) || typeof external === 'string' || external instanceof RegExp) { | ||
external = builtins.concat(external as string[]); | ||
} else if (typeof external === 'function') { | ||
const original = external; | ||
external = function (source, importer, isResolved) { | ||
if (builtins.includes(source)) { | ||
return true; | ||
} | ||
return original(source, importer, isResolved); | ||
}; | ||
} else { | ||
external = builtins; | ||
} | ||
config.build.rollupOptions.external = external; | ||
export function onBuildDone(callback: () => void) { | ||
return { | ||
name: '@electron-forge/plugin-vite:build-done', | ||
closeBundle() { | ||
callback(); | ||
}, | ||
}; | ||
} as Plugin; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.