@@ -254,34 +254,40 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
254254 if ( buildOptions . assets . length ) {
255255 const copyWebpackPluginPatterns = buildOptions . assets . map ( ( asset : AssetPatternClass ) => {
256256 // Resolve input paths relative to workspace root and add slash at the end.
257- asset . input = path . resolve ( root , asset . input ) . replace ( / \\ / g, '/' ) ;
258- asset . input = asset . input . endsWith ( '/' ) ? asset . input : asset . input + '/' ;
259- asset . output = asset . output . endsWith ( '/' ) ? asset . output : asset . output + '/' ;
260-
261- if ( asset . output . startsWith ( '..' ) ) {
262- const message = 'An asset cannot be written to a location outside of the output path.' ;
263- throw new Error ( message ) ;
257+ // tslint:disable-next-line: prefer-const
258+ let { input, output, ignore = [ ] , glob } = asset ;
259+ input = path . resolve ( root , input ) . replace ( / \\ / g, '/' ) ;
260+ input = input . endsWith ( '/' ) ? input : input + '/' ;
261+ output = output . endsWith ( '/' ) ? output : output + '/' ;
262+
263+ if ( output . startsWith ( '..' ) ) {
264+ throw new Error ( 'An asset cannot be written to a location outside of the output path.' ) ;
264265 }
265266
266267 return {
267- context : asset . input ,
268+ context : input ,
268269 // Now we remove starting slash to make Webpack place it from the output root.
269- to : asset . output . replace ( / ^ \/ / , '' ) ,
270- ignore : asset . ignore ,
271- from : {
272- glob : asset . glob ,
270+ to : output . replace ( / ^ \/ / , '' ) ,
271+ from : glob ,
272+ noErrorOnMissing : true ,
273+ globOptions : {
273274 dot : true ,
275+ ignore : [
276+ '.gitkeep' ,
277+ '**/.DS_Store' ,
278+ '**/Thumbs.db' ,
279+ // Negate patterns needs to be absolute because copy-webpack-plugin uses absolute globs which
280+ // causes negate patterns not to match.
281+ // See: https://github.com/webpack-contrib/copy-webpack-plugin/issues/498#issuecomment-639327909
282+ ...ignore ,
283+ ] . map ( i => path . posix . join ( input , i ) ) ,
274284 } ,
275285 } ;
276286 } ) ;
277287
278- const copyWebpackPluginOptions = { ignore : [ '.gitkeep' , '**/.DS_Store' , '**/Thumbs.db' ] } ;
279-
280- const copyWebpackPluginInstance = new CopyWebpackPlugin (
281- copyWebpackPluginPatterns ,
282- copyWebpackPluginOptions ,
283- ) ;
284- extraPlugins . push ( copyWebpackPluginInstance ) ;
288+ extraPlugins . push ( new CopyWebpackPlugin ( {
289+ patterns : copyWebpackPluginPatterns ,
290+ } ) ) ;
285291 }
286292
287293 if ( buildOptions . progress ) {
0 commit comments