@@ -194,37 +194,43 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
194194 }
195195
196196 // process asset entries
197- if ( buildOptions . assets ) {
197+ if ( buildOptions . assets . length ) {
198198 const copyWebpackPluginPatterns = buildOptions . assets . map ( ( asset : AssetPatternClass ) => {
199199 // Resolve input paths relative to workspace root and add slash at the end.
200- asset . input = path . resolve ( root , asset . input ) . replace ( / \\ / g, '/' ) ;
201- asset . input = asset . input . endsWith ( '/' ) ? asset . input : asset . input + '/' ;
202- asset . output = asset . output . endsWith ( '/' ) ? asset . output : asset . output + '/' ;
203-
204- if ( asset . output . startsWith ( '..' ) ) {
205- const message = 'An asset cannot be written to a location outside of the output path.' ;
206- throw new Error ( message ) ;
200+ // tslint:disable-next-line: prefer-const
201+ let { input, output, ignore = [ ] , glob } = asset ;
202+ input = path . resolve ( root , input ) . replace ( / \\ / g, '/' ) ;
203+ input = input . endsWith ( '/' ) ? input : input + '/' ;
204+ output = output . endsWith ( '/' ) ? output : output + '/' ;
205+
206+ if ( output . startsWith ( '..' ) ) {
207+ throw new Error ( 'An asset cannot be written to a location outside of the output path.' ) ;
207208 }
208209
209210 return {
210- context : asset . input ,
211+ context : input ,
211212 // Now we remove starting slash to make Webpack place it from the output root.
212- to : asset . output . replace ( / ^ \/ / , '' ) ,
213- ignore : asset . ignore ,
214- from : {
215- glob : asset . glob ,
213+ to : output . replace ( / ^ \/ / , '' ) ,
214+ from : glob ,
215+ noErrorOnMissing : true ,
216+ globOptions : {
216217 dot : true ,
218+ ignore : [
219+ '.gitkeep' ,
220+ '**/.DS_Store' ,
221+ '**/Thumbs.db' ,
222+ // Negate patterns needs to be absolute because copy-webpack-plugin uses absolute globs which
223+ // causes negate patterns not to match.
224+ // See: https://github.com/webpack-contrib/copy-webpack-plugin/issues/498#issuecomment-639327909
225+ ...ignore ,
226+ ] . map ( i => path . posix . join ( input , i ) ) ,
217227 } ,
218228 } ;
219229 } ) ;
220230
221- const copyWebpackPluginOptions = { ignore : [ '.gitkeep' , '**/.DS_Store' , '**/Thumbs.db' ] } ;
222-
223- const copyWebpackPluginInstance = new CopyWebpackPlugin (
224- copyWebpackPluginPatterns ,
225- copyWebpackPluginOptions ,
226- ) ;
227- extraPlugins . push ( copyWebpackPluginInstance ) ;
231+ extraPlugins . push ( new CopyWebpackPlugin ( {
232+ patterns : copyWebpackPluginPatterns ,
233+ } ) ) ;
228234 }
229235
230236 if ( buildOptions . progress ) {
0 commit comments