@@ -201,12 +201,31 @@ async function initialize(
201
201
i18n : I18nOptions ;
202
202
} > {
203
203
const originalOutputPath = options . outputPath ;
204
+
205
+ // Assets are processed directly by the builder except when watching
206
+ const adjustedOptions = options . watch ? options : { ...options , assets : [ ] } ;
207
+
204
208
const {
205
209
config,
206
210
projectRoot,
207
211
projectSourceRoot,
208
212
i18n,
209
- } = await buildBrowserWebpackConfigFromContext ( options , context , host , true ) ;
213
+ } = await buildBrowserWebpackConfigFromContext ( adjustedOptions , context , host , true ) ;
214
+
215
+ // Validate asset option values if processed directly
216
+ if ( options . assets ?. length && ! adjustedOptions . assets ?. length ) {
217
+ normalizeAssetPatterns (
218
+ options . assets ,
219
+ new virtualFs . SyncDelegateHost ( host ) ,
220
+ normalize ( context . workspaceRoot ) ,
221
+ normalize ( projectRoot ) ,
222
+ projectSourceRoot === undefined ? undefined : normalize ( projectSourceRoot ) ,
223
+ ) . forEach ( ( { output } ) => {
224
+ if ( output . startsWith ( '..' ) ) {
225
+ throw new Error ( 'An asset cannot be written to a location outside of the output path.' ) ;
226
+ }
227
+ } ) ;
228
+ }
210
229
211
230
let transformedConfig ;
212
231
if ( webpackConfigurationTransform ) {
@@ -573,27 +592,6 @@ export function buildWebpackBrowser(
573
592
executor . stop ( ) ;
574
593
}
575
594
576
- // Copy assets
577
- if ( options . assets ) {
578
- try {
579
- await copyAssets (
580
- normalizeAssetPatterns (
581
- options . assets ,
582
- new virtualFs . SyncDelegateHost ( host ) ,
583
- root ,
584
- normalize ( projectRoot ) ,
585
- projectSourceRoot === undefined ? undefined : normalize ( projectSourceRoot ) ,
586
- ) ,
587
- Array . from ( outputPaths . values ( ) ) ,
588
- context . workspaceRoot ,
589
- ) ;
590
- } catch ( err ) {
591
- context . logger . error ( 'Unable to copy assets: ' + err . message ) ;
592
-
593
- return { success : false } ;
594
- }
595
- }
596
-
597
595
type ArrayElement < A > = A extends ReadonlyArray < infer T > ? T : never ;
598
596
function generateBundleInfoStats (
599
597
id : string | number ,
@@ -698,6 +696,27 @@ export function buildWebpackBrowser(
698
696
}
699
697
}
700
698
699
+ // Copy assets
700
+ if ( ! options . watch && options . assets ) {
701
+ try {
702
+ await copyAssets (
703
+ normalizeAssetPatterns (
704
+ options . assets ,
705
+ new virtualFs . SyncDelegateHost ( host ) ,
706
+ root ,
707
+ normalize ( projectRoot ) ,
708
+ projectSourceRoot === undefined ? undefined : normalize ( projectSourceRoot ) ,
709
+ ) ,
710
+ Array . from ( outputPaths . values ( ) ) ,
711
+ context . workspaceRoot ,
712
+ ) ;
713
+ } catch ( err ) {
714
+ context . logger . error ( 'Unable to copy assets: ' + err . message ) ;
715
+
716
+ return { success : false } ;
717
+ }
718
+ }
719
+
701
720
if ( options . index ) {
702
721
for ( const [ locale , outputPath ] of outputPaths . entries ( ) ) {
703
722
let localeBaseHref ;
0 commit comments