@@ -27,18 +27,24 @@ module.exports = function () {
2727
2828 if ( ! config . build . rollupOptions ) config . build . rollupOptions = { } ;
2929 if ( ! config . build . rollupOptions . output ) config . build . rollupOptions . output = { } ;
30+
31+ const prodExternals = [ ...builtinModules . filter ( e => ! e . startsWith ( '_' ) ) , 'electron' ] ;
32+
33+ const modifyOutput = output => {
34+ if ( ! output . format ) {
35+ // the packaged Electron app should use "cjs"
36+ output . format = 'cjs' ;
37+ }
38+
39+ // make builtin modules & electron external when rollup
40+ output . external = [ ...( output . external || [ ] ) , ...prodExternals ] ;
41+ } ;
3042 if ( Array . isArray ( config . build . rollupOptions . output ) ) {
3143 config . build . rollupOptions . output . forEach ( output => {
32- if ( ! output . format ) {
33- // the packaged Electron app should use "cjs"
34- output . format = 'cjs' ;
35- }
44+ modifyOutput ( output ) ;
3645 } ) ;
3746 } else {
38- if ( ! config . build . rollupOptions . output . format ) {
39- // the packaged Electron app should use "cjs"
40- config . build . rollupOptions . output . format = 'cjs' ;
41- }
47+ modifyOutput ( config . build . rollupOptions . output ) ;
4248 }
4349
4450 // ----------------------------------------
@@ -70,7 +76,7 @@ module.exports = function () {
7076
7177/**
7278 * @typedef {Record<string, import('vite-plugin-optimizer').ResultDescription> } ExportCollected
73- * @type {(modules: string[]) => ExportCollected }
79+ * @type {(modules: string[]) => ExportCollected }
7480 */
7581function builtinModulesExport ( modules ) {
7682 return modules . map ( ( moduleId ) => {
@@ -90,7 +96,6 @@ ${exportMembers}
9096 * @type {ExportCollected }
9197 */
9298 const collect = {
93- //
9499 [ moduleId ] : {
95100 alias : { find : new RegExp ( `^(node:)?${ moduleId } $` ) } ,
96101 code : nodeModuleCode ,
0 commit comments