@@ -194,37 +194,43 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
194
194
}
195
195
196
196
// process asset entries
197
- if ( buildOptions . assets ) {
197
+ if ( buildOptions . assets . length ) {
198
198
const copyWebpackPluginPatterns = buildOptions . assets . map ( ( asset : AssetPatternClass ) => {
199
199
// 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.' ) ;
207
208
}
208
209
209
210
return {
210
- context : asset . input ,
211
+ context : input ,
211
212
// 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 : {
216
217
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 ) ) ,
217
227
} ,
218
228
} ;
219
229
} ) ;
220
230
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
+ } ) ) ;
228
234
}
229
235
230
236
if ( buildOptions . progress ) {
0 commit comments