@@ -3,8 +3,9 @@ const path = require("path");
3
3
const worker = require ( "./worker" ) ;
4
4
const schema = require ( "./loader-options.json" ) ;
5
5
const {
6
- isAbsoluteURL,
7
6
IMAGE_MINIMIZER_PLUGIN_INFO_MAPPINGS ,
7
+ ABSOLUTE_URL_REGEX ,
8
+ WINDOWS_PATH_REGEX ,
8
9
} = require ( "./utils.js" ) ;
9
10
10
11
/** @typedef {import("schema-utils/declarations/validate").Schema } Schema */
@@ -33,14 +34,14 @@ const {
33
34
/**
34
35
* @template T
35
36
* @param {import("webpack").LoaderContext<LoaderOptions<T>> } loaderContext
36
- * @param {boolean } isAbsolute
37
37
* @param {WorkerResult } output
38
38
* @param {string } query
39
39
*/
40
- function changeResource ( loaderContext , isAbsolute , output , query ) {
41
- loaderContext . resourcePath = isAbsolute
42
- ? output . filename
43
- : path . join ( loaderContext . rootContext , output . filename ) ;
40
+ function changeResource ( loaderContext , output , query ) {
41
+ loaderContext . resourcePath = path . join (
42
+ loaderContext . rootContext ,
43
+ output . filename ,
44
+ ) ;
44
45
loaderContext . resourceQuery = query ;
45
46
}
46
47
@@ -203,11 +204,11 @@ async function loader(content) {
203
204
}
204
205
}
205
206
206
- let isAbsolute = isAbsoluteURL ( this . resourcePath ) ;
207
-
208
- const filename = isAbsolute
209
- ? this . resourcePath
210
- : path . relative ( this . rootContext , this . resourcePath ) ;
207
+ const filename =
208
+ ABSOLUTE_URL_REGEX . test ( this . resourcePath ) &&
209
+ ! WINDOWS_PATH_REGEX . test ( this . resourcePath )
210
+ ? this . resourcePath
211
+ : this . utils . contextify ( this . rootContext , this . resourcePath ) ;
211
212
212
213
const minifyOptions =
213
214
/** @type {import("./index").InternalWorkerOptions<T> } */ ( {
@@ -264,9 +265,8 @@ async function loader(content) {
264
265
query = query . length > 0 ? `?${ query } ` : "" ;
265
266
}
266
267
267
- isAbsolute = isAbsoluteURL ( output . filename ) ;
268
268
// Old approach for `file-loader` and other old loaders
269
- changeResource ( this , isAbsolute , output , query ) ;
269
+ changeResource ( this , output , query ) ;
270
270
271
271
// Change name of assets modules after generator
272
272
if ( this . _module && ! this . _module . matchResource ) {
0 commit comments