@@ -61,9 +61,11 @@ import {
61
61
BuildBrowserFeatures ,
62
62
deleteOutputDir ,
63
63
fullDifferential ,
64
+ normalizeAssetPatterns ,
64
65
normalizeOptimization ,
65
66
normalizeSourceMaps ,
66
67
} from '../utils' ;
68
+ import { copyAssets } from '../utils/copy-assets' ;
67
69
import { I18nOptions , createI18nOptions } from '../utils/i18n-options' ;
68
70
import { manglingDisabled } from '../utils/mangle-options' ;
69
71
import {
@@ -216,13 +218,14 @@ export function buildWebpackBrowser(
216
218
) : Observable < BrowserBuilderOutput > {
217
219
const host = new NodeJsSyncHost ( ) ;
218
220
const root = normalize ( context . workspaceRoot ) ;
221
+ const baseOutputPath = path . resolve ( context . workspaceRoot , options . outputPath ) ;
219
222
220
223
// Check Angular version.
221
224
assertCompatibleAngularVersion ( context . workspaceRoot , context . logger ) ;
222
225
223
226
return from ( initialize ( options , context , host , transforms . webpackConfiguration ) ) . pipe (
224
227
// tslint:disable-next-line: no-big-function
225
- switchMap ( ( { config : configs , projectRoot, i18n } ) => {
228
+ switchMap ( ( { config : configs , projectRoot, projectSourceRoot , i18n } ) => {
226
229
const tsConfig = readTsconfig ( options . tsConfig , context . workspaceRoot ) ;
227
230
const target = tsConfig . options . target || ScriptTarget . ES5 ;
228
231
const buildBrowserFeatures = new BuildBrowserFeatures ( projectRoot , target ) ;
@@ -355,7 +358,7 @@ export function buildWebpackBrowser(
355
358
356
359
// Retrieve the content/map for the file
357
360
// NOTE: Additional future optimizations will read directly from memory
358
- let filename = path . resolve ( getSystemPath ( root ) , options . outputPath , file . file ) ;
361
+ let filename = path . join ( baseOutputPath , file . file ) ;
359
362
const code = fs . readFileSync ( filename , 'utf8' ) ;
360
363
let map ;
361
364
if ( actionOptions . sourceMaps ) {
@@ -628,6 +631,27 @@ export function buildWebpackBrowser(
628
631
629
632
context . logger . info ( 'ES5 bundle generation complete.' ) ;
630
633
634
+ // Copy assets
635
+ if ( options . assets ) {
636
+ try {
637
+ await copyAssets (
638
+ normalizeAssetPatterns (
639
+ options . assets ,
640
+ new virtualFs . SyncDelegateHost ( host ) ,
641
+ root ,
642
+ normalize ( projectRoot ) ,
643
+ projectSourceRoot === undefined ? undefined : normalize ( projectSourceRoot ) ,
644
+ ) ,
645
+ [ baseOutputPath ] ,
646
+ context . workspaceRoot ,
647
+ ) ;
648
+ } catch ( err ) {
649
+ context . logger . error ( 'Unable to copy assets: ' + err . message ) ;
650
+
651
+ return { success : false } ;
652
+ }
653
+ }
654
+
631
655
type ArrayElement < A > = A extends ReadonlyArray < infer T > ? T : never ;
632
656
function generateBundleInfoStats (
633
657
id : string | number ,
@@ -703,10 +727,7 @@ export function buildWebpackBrowser(
703
727
if ( options . index ) {
704
728
return writeIndexHtml ( {
705
729
host,
706
- outputPath : resolve (
707
- root ,
708
- join ( normalize ( options . outputPath ) , getIndexOutputFile ( options ) ) ,
709
- ) ,
730
+ outputPath : join ( normalize ( baseOutputPath ) , getIndexOutputFile ( options ) ) ,
710
731
indexPath : join ( root , getIndexInputFile ( options ) ) ,
711
732
files,
712
733
noModuleFiles,
@@ -739,7 +760,7 @@ export function buildWebpackBrowser(
739
760
host ,
740
761
root ,
741
762
normalize ( projectRoot ) ,
742
- resolve ( root , normalize ( options . outputPath ) ) ,
763
+ normalize ( baseOutputPath ) ,
743
764
options . baseHref || '/' ,
744
765
options . ngswConfigPath ,
745
766
) . then (
@@ -756,7 +777,7 @@ export function buildWebpackBrowser(
756
777
( {
757
778
...event ,
758
779
// If we use differential loading, both configs have the same outputs
759
- outputPath : path . resolve ( context . workspaceRoot , options . outputPath ) ,
780
+ outputPath : baseOutputPath ,
760
781
} as BrowserBuilderOutput ) ,
761
782
) ,
762
783
) ;
0 commit comments