@@ -180,11 +180,20 @@ Specify a filesystem path where the target file(s) will be placed.
180180 loader: ' file-loader' ,
181181 options: {
182182 name: ' [path][name].[ext]' ,
183- outputPath : (url , resourcePath ) => {
183+ outputPath : (url , resourcePath , context ) => {
184184 // `resourcePath` is original absolute path to asset
185+ // `context` is directory where stored asset (`rootContext`) or `context` option
186+
187+ // To get relative path you can use
188+ // const relativePath = path.relative(context, resourcePath);
189+
185190 if (/ my-custom-image\. png/ .test (resourcePath)) {
186191 return ` other_output_path/${ url} `
187192 }
193+
194+ if (/ images/ .test (context)) {
195+ return ` image_output_path/${ url} ` ;
196+ }
188197
189198 return ` output_path/${ url} ` ;
190199 },
@@ -224,11 +233,20 @@ Specifies a custom public path for the target file(s).
224233 loader: ' file-loader' ,
225234 options: {
226235 name: ' [path][name].[ext]' ,
227- publicPath: (url, resourcePath) {
236+ publicPath : (url , resourcePath , context ) => {
228237 // `resourcePath` is original absolute path to asset
238+ // `context` is directory where stored asset (`rootContext`) or `context` option
239+
240+ // To get relative path you can use
241+ // const relativePath = path.relative(context, resourcePath);
242+
229243 if (/ my-custom-image\. png/ .test (resourcePath)) {
230244 return ` other_public_path/${ url} `
231245 }
246+
247+ if (/ images/ .test (context)) {
248+ return ` image_output_path/${ url} ` ;
249+ }
232250
233251 return ` public_path/${ url} ` ;
234252 }
0 commit comments