@@ -185,27 +185,37 @@ function getCommonConfig(wco) {
185185 if ( buildOptions . assets . length ) {
186186 const copyWebpackPluginPatterns = buildOptions . assets . map ( ( asset ) => {
187187 // Resolve input paths relative to workspace root and add slash at the end.
188- asset . input = path . resolve ( root , asset . input ) . replace ( / \\ / g, '/' ) ;
189- asset . input = asset . input . endsWith ( '/' ) ? asset . input : asset . input + '/' ;
190- asset . output = asset . output . endsWith ( '/' ) ? asset . output : asset . output + '/' ;
191- if ( asset . output . startsWith ( '..' ) ) {
192- const message = 'An asset cannot be written to a location outside of the output path.' ;
193- throw new Error ( message ) ;
188+ // tslint:disable-next-line: prefer-const
189+ let { input, output, ignore = [ ] , glob } = asset ;
190+ input = path . resolve ( root , input ) . replace ( / \\ / g, '/' ) ;
191+ input = input . endsWith ( '/' ) ? input : input + '/' ;
192+ output = output . endsWith ( '/' ) ? output : output + '/' ;
193+ if ( output . startsWith ( '..' ) ) {
194+ throw new Error ( 'An asset cannot be written to a location outside of the output path.' ) ;
194195 }
195196 return {
196- context : asset . input ,
197+ context : input ,
197198 // Now we remove starting slash to make Webpack place it from the output root.
198- to : asset . output . replace ( / ^ \/ / , '' ) ,
199- ignore : asset . ignore ,
200- from : {
201- glob : asset . glob ,
199+ to : output . replace ( / ^ \/ / , '' ) ,
200+ from : glob ,
201+ noErrorOnMissing : true ,
202+ globOptions : {
202203 dot : true ,
204+ ignore : [
205+ '.gitkeep' ,
206+ '**/.DS_Store' ,
207+ '**/Thumbs.db' ,
208+ // Negate patterns needs to be absolute because copy-webpack-plugin uses absolute globs which
209+ // causes negate patterns not to match.
210+ // See: https://github.com/webpack-contrib/copy-webpack-plugin/issues/498#issuecomment-639327909
211+ ...ignore ,
212+ ] . map ( i => path . posix . join ( input , i ) ) ,
203213 } ,
204214 } ;
205215 } ) ;
206- const copyWebpackPluginOptions = { ignore : [ '.gitkeep' , '**/.DS_Store' , '**/Thumbs.db' ] } ;
207- const copyWebpackPluginInstance = new CopyWebpackPlugin ( copyWebpackPluginPatterns , copyWebpackPluginOptions ) ;
208- extraPlugins . push ( copyWebpackPluginInstance ) ;
216+ extraPlugins . push ( new CopyWebpackPlugin ( {
217+ patterns : copyWebpackPluginPatterns ,
218+ } ) ) ;
209219 }
210220 if ( buildOptions . progress ) {
211221 extraPlugins . push ( new ProgressPlugin ( { profile : buildOptions . verbose } ) ) ;
0 commit comments