@@ -141,30 +141,40 @@ function getCommonConfig(wco) {
141141 } ) ;
142142 }
143143 // process asset entries
144- if ( buildOptions . assets ) {
144+ if ( buildOptions . assets . length ) {
145145 const copyWebpackPluginPatterns = buildOptions . assets . map ( ( asset ) => {
146146 // Resolve input paths relative to workspace root and add slash at the end.
147- asset . input = path . resolve ( root , asset . input ) . replace ( / \\ / g, '/' ) ;
148- asset . input = asset . input . endsWith ( '/' ) ? asset . input : asset . input + '/' ;
149- asset . output = asset . output . endsWith ( '/' ) ? asset . output : asset . output + '/' ;
150- if ( asset . output . startsWith ( '..' ) ) {
151- const message = 'An asset cannot be written to a location outside of the output path.' ;
152- throw new Error ( message ) ;
147+ // tslint:disable-next-line: prefer-const
148+ let { input, output, ignore = [ ] , glob } = asset ;
149+ input = path . resolve ( root , input ) . replace ( / \\ / g, '/' ) ;
150+ input = input . endsWith ( '/' ) ? input : input + '/' ;
151+ output = output . endsWith ( '/' ) ? output : output + '/' ;
152+ if ( output . startsWith ( '..' ) ) {
153+ throw new Error ( 'An asset cannot be written to a location outside of the output path.' ) ;
153154 }
154155 return {
155- context : asset . input ,
156+ context : input ,
156157 // Now we remove starting slash to make Webpack place it from the output root.
157- to : asset . output . replace ( / ^ \/ / , '' ) ,
158- ignore : asset . ignore ,
159- from : {
160- glob : asset . glob ,
158+ to : output . replace ( / ^ \/ / , '' ) ,
159+ from : glob ,
160+ noErrorOnMissing : true ,
161+ globOptions : {
161162 dot : true ,
163+ ignore : [
164+ '.gitkeep' ,
165+ '**/.DS_Store' ,
166+ '**/Thumbs.db' ,
167+ // Negate patterns needs to be absolute because copy-webpack-plugin uses absolute globs which
168+ // causes negate patterns not to match.
169+ // See: https://github.com/webpack-contrib/copy-webpack-plugin/issues/498#issuecomment-639327909
170+ ...ignore ,
171+ ] . map ( i => path . posix . join ( input , i ) ) ,
162172 } ,
163173 } ;
164174 } ) ;
165- const copyWebpackPluginOptions = { ignore : [ '.gitkeep' , '**/.DS_Store' , '**/Thumbs.db' ] } ;
166- const copyWebpackPluginInstance = new CopyWebpackPlugin ( copyWebpackPluginPatterns , copyWebpackPluginOptions ) ;
167- extraPlugins . push ( copyWebpackPluginInstance ) ;
175+ extraPlugins . push ( new CopyWebpackPlugin ( {
176+ patterns : copyWebpackPluginPatterns ,
177+ } ) ) ;
168178 }
169179 if ( buildOptions . progress ) {
170180 extraPlugins . push ( new ProgressPlugin ( { profile : buildOptions . verbose } ) ) ;
0 commit comments