@@ -15,7 +15,7 @@ import {
1515 GLOBAL_DEFS_FOR_TERSER_WITH_AOT ,
1616 VERSION as NG_VERSION ,
1717} from '@angular/compiler-cli' ;
18- import CopyWebpackPlugin from 'copy-webpack-plugin' ;
18+ import CopyWebpackPlugin , { ObjectPattern } from 'copy-webpack-plugin' ;
1919import { createHash } from 'crypto' ;
2020import { createWriteStream , existsSync , promises as fsPromises } from 'fs' ;
2121import * as path from 'path' ;
@@ -212,40 +212,43 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
212212
213213 // process asset entries
214214 if ( buildOptions . assets . length ) {
215- const copyWebpackPluginPatterns = buildOptions . assets . map ( ( asset : AssetPatternClass ) => {
216- // Resolve input paths relative to workspace root and add slash at the end.
217- // eslint-disable-next-line prefer-const
218- let { input, output, ignore = [ ] , glob } = asset ;
219- input = path . resolve ( root , input ) . replace ( / \\ / g, '/' ) ;
220- input = input . endsWith ( '/' ) ? input : input + '/' ;
221- output = output . endsWith ( '/' ) ? output : output + '/' ;
222-
223- if ( output . startsWith ( '..' ) ) {
224- throw new Error ( 'An asset cannot be written to a location outside of the output path.' ) ;
225- }
215+ const copyWebpackPluginPatterns = buildOptions . assets . map (
216+ ( asset : AssetPatternClass , index : number ) : ObjectPattern => {
217+ // Resolve input paths relative to workspace root and add slash at the end.
218+ // eslint-disable-next-line prefer-const
219+ let { input, output, ignore = [ ] , glob } = asset ;
220+ input = path . resolve ( root , input ) . replace ( / \\ / g, '/' ) ;
221+ input = input . endsWith ( '/' ) ? input : input + '/' ;
222+ output = output . endsWith ( '/' ) ? output : output + '/' ;
223+
224+ if ( output . startsWith ( '..' ) ) {
225+ throw new Error ( 'An asset cannot be written to a location outside of the output path.' ) ;
226+ }
226227
227- return {
228- context : input ,
229- // Now we remove starting slash to make Webpack place it from the output root.
230- to : output . replace ( / ^ \/ / , '' ) ,
231- from : glob ,
232- noErrorOnMissing : true ,
233- force : true ,
234- globOptions : {
235- dot : true ,
236- followSymbolicLinks : ! ! asset . followSymlinks ,
237- ignore : [
238- '.gitkeep' ,
239- '**/.DS_Store' ,
240- '**/Thumbs.db' ,
241- // Negate patterns needs to be absolute because copy-webpack-plugin uses absolute globs which
242- // causes negate patterns not to match.
243- // See: https://github.com/webpack-contrib/copy-webpack-plugin/issues/498#issuecomment-639327909
244- ...ignore ,
245- ] . map ( ( i ) => path . posix . join ( input , i ) ) ,
246- } ,
247- } ;
248- } ) ;
228+ return {
229+ context : input ,
230+ // Now we remove starting slash to make Webpack place it from the output root.
231+ to : output . replace ( / ^ \/ / , '' ) ,
232+ from : glob ,
233+ noErrorOnMissing : true ,
234+ force : true ,
235+ globOptions : {
236+ dot : true ,
237+ followSymbolicLinks : ! ! asset . followSymlinks ,
238+ ignore : [
239+ '.gitkeep' ,
240+ '**/.DS_Store' ,
241+ '**/Thumbs.db' ,
242+ // Negate patterns needs to be absolute because copy-webpack-plugin uses absolute globs which
243+ // causes negate patterns not to match.
244+ // See: https://github.com/webpack-contrib/copy-webpack-plugin/issues/498#issuecomment-639327909
245+ ...ignore ,
246+ ] . map ( ( i ) => path . posix . join ( input , i ) ) ,
247+ } ,
248+ priority : index ,
249+ } ;
250+ } ,
251+ ) ;
249252
250253 extraPlugins . push (
251254 new CopyWebpackPlugin ( {
0 commit comments