@@ -20,7 +20,7 @@ import { getIndexInputFile, getIndexOutputFile } from '../../utils/webpack-brows
2020import { resolveGlobalStyles } from '../../webpack/configs' ;
2121import { Schema as BrowserBuilderOptions , SourceMapClass } from '../browser/schema' ;
2222import { createCompilerPlugin } from './compiler-plugin' ;
23- import { bundle , logMessages } from './esbuild' ;
23+ import { DEFAULT_OUTDIR , bundle , logMessages } from './esbuild' ;
2424import { logExperimentalWarnings } from './experimental-warnings' ;
2525import { normalizeOptions } from './options' ;
2626import { bundleStylesheetText } from './stylesheets' ;
@@ -116,11 +116,13 @@ export async function execute(
116116 // Entries in the metafile are relative to the `absWorkingDir` option which is set to the workspaceRoot
117117 const relativeFilePath = path . relative ( workspaceRoot , outputFile . path ) ;
118118 const entryPoint = result . metafile ?. outputs [ relativeFilePath ] ?. entryPoint ;
119+
120+ outputFile . path = path . relative ( DEFAULT_OUTDIR , outputFile . path ) ;
121+
119122 if ( entryPoint ) {
120123 // An entryPoint value indicates an initial file
121124 initialFiles . push ( {
122- // Remove leading directory separator
123- file : outputFile . path . slice ( 1 ) ,
125+ file : outputFile . path ,
124126 name : entryPointNameLookup . get ( entryPoint ) ?? '' ,
125127 extension : path . extname ( outputFile . path ) ,
126128 } ) ;
@@ -147,7 +149,9 @@ export async function execute(
147149 ! ! options . preserveSymlinks ,
148150 ) ;
149151 for ( const [ name , files ] of Object . entries ( stylesheetEntrypoints ) ) {
150- const virtualEntryData = files . map ( ( file ) => `@import '${ file } ';` ) . join ( '\n' ) ;
152+ const virtualEntryData = files
153+ . map ( ( file ) => `@import '${ file . replace ( / \\ / g, '/' ) } ';` )
154+ . join ( '\n' ) ;
151155 const sheetResult = await bundleStylesheetText (
152156 virtualEntryData ,
153157 { virtualName : `angular:style/global;${ name } ` , resolvePath : workspaceRoot } ,
@@ -172,7 +176,7 @@ export async function execute(
172176 // The virtual stylesheets will be named `stdin` by esbuild. This must be replaced
173177 // with the actual name of the global style and the leading directory separator must
174178 // also be removed to make the path relative.
175- const sheetPath = sheetResult . path . replace ( 'stdin' , name ) . slice ( 1 ) ;
179+ const sheetPath = sheetResult . path . replace ( 'stdin' , name ) ;
176180 outputFiles . push ( createOutputFileFromText ( sheetPath , sheetResult . contents ) ) ;
177181 if ( sheetResult . map ) {
178182 outputFiles . push ( createOutputFileFromText ( sheetPath + '.map' , sheetResult . map ) ) ;
@@ -203,10 +207,13 @@ export async function execute(
203207 optimization : optimizationOptions ,
204208 crossOrigin : options . crossOrigin ,
205209 } ) ;
206- indexHtmlGenerator . readAsset = async function ( path : string ) : Promise < string > {
210+
211+ /** Virtual output path to support reading in-memory files. */
212+ const virtualOutputPath = '/' ;
213+ indexHtmlGenerator . readAsset = async function ( filePath : string ) : Promise < string > {
207214 // Remove leading directory separator
208- path = path . slice ( 1 ) ;
209- const file = outputFiles . find ( ( file ) => file . path === path ) ;
215+ const relativefilePath = path . relative ( virtualOutputPath , filePath ) ;
216+ const file = outputFiles . find ( ( file ) => file . path === relativefilePath ) ;
210217 if ( file ) {
211218 return file . text ;
212219 }
@@ -217,7 +224,7 @@ export async function execute(
217224 const { content, warnings, errors } = await indexHtmlGenerator . process ( {
218225 baseHref : options . baseHref ,
219226 lang : undefined ,
220- outputPath : '/' , // Virtual output path to support reading in-memory files
227+ outputPath : virtualOutputPath ,
221228 files : initialFiles ,
222229 } ) ;
223230
@@ -280,7 +287,7 @@ async function bundleCode(
280287 metafile : true ,
281288 minify : optimizationOptions . scripts ,
282289 pure : [ 'forwardRef' ] ,
283- outdir : '/' ,
290+ outdir : DEFAULT_OUTDIR ,
284291 sourcemap : sourcemapOptions . scripts && ( sourcemapOptions . hidden ? 'external' : true ) ,
285292 splitting : true ,
286293 tsconfig,
0 commit comments