@@ -32,7 +32,7 @@ import {
3232} from '../../utils/dev-server' ;
3333import { RebuildHubs } from '../../utils/rebuild-events' ;
3434import { updateIndexHtml } from '../../utils/updateIndexHtml' ;
35- import { existsSync , mkdirSync , rmdirSync } from 'fs' ;
35+ import { existsSync , mkdirSync , rmSync } from 'fs' ;
3636import {
3737 EsBuildResult ,
3838 MemResults ,
@@ -80,7 +80,15 @@ export async function* runBuilder(
8080 const config = await loadFederationConfig ( fedOptions ) ;
8181 const externals = getExternals ( config ) ;
8282
83- options . externalDependencies = externals . filter ( ( e ) => e !== 'tslib' ) ;
83+ // options.externalDependencies = externals.filter((e) => e !== 'tslib');
84+ const plugins = [
85+ {
86+ name : 'externals' ,
87+ setup ( build ) {
88+ build . initialOptions . external = externals . filter ( ( e ) => e !== 'tslib' ) ;
89+ } ,
90+ } ,
91+ ] ;
8492
8593 // for await (const r of buildEsbuildBrowser(options, context as any, { write: false })) {
8694 // const output = r.outputFiles ||[];
@@ -103,23 +111,35 @@ export async function* runBuilder(
103111 let lastResult : { success : boolean } | undefined ;
104112
105113 if ( existsSync ( options . outputPath ) ) {
106- rmdirSync ( options . outputPath , { recursive : true } ) ;
114+ rmSync ( options . outputPath , { recursive : true } ) ;
107115 }
108116
109117 if ( ! existsSync ( options . outputPath ) ) {
110118 mkdirSync ( options . outputPath , { recursive : true } ) ;
111119 }
112120
113121 if ( ! write ) {
114- setMemResultHandler ( ( outFiles ) => {
115- memResults . add ( outFiles . map ( ( f ) => new EsBuildResult ( f ) ) ) ;
122+ setMemResultHandler ( ( outFiles , outDir ) => {
123+ const fullOutDir = outDir
124+ ? path . join ( fedOptions . workspaceRoot , outDir )
125+ : null ;
126+ memResults . add ( outFiles . map ( ( f ) => new EsBuildResult ( f , fullOutDir ) ) ) ;
116127 } ) ;
117128 }
118129
130+ await buildForFederation ( config , fedOptions , externals ) ;
131+
132+ options . deleteOutputPath = false ;
133+
119134 // builderRun.output.subscribe(async (output) => {
120- for await ( const output of buildEsbuildBrowser ( options , context as any , {
121- write,
122- } ) ) {
135+ for await ( const output of buildEsbuildBrowser (
136+ options ,
137+ context as any ,
138+ {
139+ write,
140+ } ,
141+ plugins
142+ ) ) {
123143 lastResult = output ;
124144
125145 if ( ! output . success ) {
@@ -144,10 +164,6 @@ export async function* runBuilder(
144164 updateIndexHtml ( fedOptions ) ;
145165 }
146166
147- if ( first ) {
148- await buildForFederation ( config , fedOptions , externals ) ;
149- }
150-
151167 if ( first && runServer ) {
152168 startServer ( nfOptions , options . outputPath , memResults ) ;
153169 }
0 commit comments