File tree Expand file tree Collapse file tree 2 files changed +53
-1
lines changed Expand file tree Collapse file tree 2 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ module.exports.default = function loader(source) {
56
56
// The "source" part of the regexp is base64 encoded
57
57
// in case it contains characters that don't work with
58
58
// the "inline loader" syntax
59
- const pattern = new RegExp (
59
+ const pattern = options . regExp || new RegExp (
60
60
Buffer . from ( options . patternSource , 'base64' ) . toString ( ) ,
61
61
options . patternFlags
62
62
) ;
@@ -69,6 +69,23 @@ module.exports.default = function loader(source) {
69
69
return 'module.exports = "";' ;
70
70
}
71
71
72
+ // Add the "regExp" option (needed to use the [N] placeholder
73
+ // see: https://github.com/webpack-contrib/file-loader#n)
74
+ options . regExp = pattern ;
75
+
76
+ // Remove copy-files-loader's custom options (in case the
77
+ // file-loader starts looking for thing it doesn't expect)
78
+ delete options . patternSource ;
79
+ delete options . patternFlags ;
80
+
81
+ // Update loader's options.
82
+ this . loaders . forEach ( loader => {
83
+ if ( __filename === loader . path ) {
84
+ loader . options = options ;
85
+ delete loader . query ;
86
+ }
87
+ } ) ;
88
+
72
89
// If everything is OK, let the file-loader do the copy
73
90
return fileLoader . bind ( this ) ( source ) ;
74
91
} ;
Original file line number Diff line number Diff line change @@ -2206,6 +2206,41 @@ module.exports = {
2206
2206
done ( ) ;
2207
2207
} ) ;
2208
2208
} ) ;
2209
+
2210
+ it ( 'Can use the "[N]" placeholder' , ( done ) => {
2211
+ const config = createWebpackConfig ( 'www/build' , 'production' ) ;
2212
+ config . addEntry ( 'main' , './js/no_require' ) ;
2213
+ config . setPublicPath ( '/build' ) ;
2214
+ config . copyFiles ( {
2215
+ from : './images' ,
2216
+ pattern : / ( s y m f o n y ) _ ( l o g o ) \. p n g / ,
2217
+ to : '[path][2]_[1].[ext]' ,
2218
+ includeSubdirectories : false
2219
+ } ) ;
2220
+
2221
+ testSetup . runWebpack ( config , ( webpackAssert ) => {
2222
+ expect ( config . outputPath ) . to . be . a . directory ( )
2223
+ . with . files ( [
2224
+ 'entrypoints.json' ,
2225
+ 'runtime.js' ,
2226
+ 'main.js' ,
2227
+ 'manifest.json' ,
2228
+ 'logo_symfony.png'
2229
+ ] ) ;
2230
+
2231
+ webpackAssert . assertManifestPath (
2232
+ 'build/main.js' ,
2233
+ '/build/main.js'
2234
+ ) ;
2235
+
2236
+ webpackAssert . assertManifestPath (
2237
+ 'build/symfony_logo.png' ,
2238
+ '/build/logo_symfony.png'
2239
+ ) ;
2240
+
2241
+ done ( ) ;
2242
+ } ) ;
2243
+ } ) ;
2209
2244
} ) ;
2210
2245
2211
2246
describe ( 'entrypoints.json & splitChunks()' , ( ) => {
You can’t perform that action at this time.
0 commit comments