7
7
var path = require ( 'path' ) ,
8
8
loaderUtils = require ( 'loader-utils' ) ;
9
9
10
+ /**
11
+ * We require the lost functionality from loaderUtils.isUrlRequest()@>=3.0.0
12
+ * https://github.com/webpack/loader-utils/blob/47d0be719a8243e7805e8070fcec857427529508/lib/isUrlRequest.js
13
+ */
14
+ function isUrlRequest ( url , root ) {
15
+ // An URL is not an request if
16
+
17
+ // 1. It's an absolute url and it is not `windows` path like `C:\dir\file`
18
+ if ( / ^ [ a - z ] [ a - z 0 - 9 + . - ] * : / i. test ( url ) && ! path . win32 . isAbsolute ( url ) ) {
19
+ return false ;
20
+ }
21
+
22
+ // 2. It's a protocol-relative
23
+ if ( / ^ \/ \/ / . test ( url ) ) {
24
+ return false ;
25
+ }
26
+
27
+ // 3. It's some kind of url for a template
28
+ if ( / ^ [ { } [ \] # * ; , ' § $ % & ( = ? ` ´ ^ ° < > ] / . test ( url ) ) {
29
+ return false ;
30
+ }
31
+
32
+ // 4. It's also not an request if root isn't set and it's a root-relative url
33
+ if ( ( root === undefined || root === false ) && / ^ \/ / . test ( url ) ) {
34
+ return false ;
35
+ }
36
+
37
+ return true ;
38
+ }
39
+
10
40
/**
11
41
* Create a value processing function for a given file path.
12
42
*
@@ -117,7 +147,7 @@ function valueProcessor({ join, root, directory }) {
117
147
* @return {boolean } True for relative uri
118
148
*/
119
149
function testIsRelative ( uri ) {
120
- return ! ! uri && loaderUtils . isUrlRequest ( uri , false ) && ! path . isAbsolute ( uri ) && ( uri . indexOf ( '~' ) !== 0 ) ;
150
+ return ! ! uri && isUrlRequest ( uri , false ) && ! path . isAbsolute ( uri ) && ( uri . indexOf ( '~' ) !== 0 ) ;
121
151
}
122
152
123
153
/**
@@ -128,7 +158,7 @@ function valueProcessor({ join, root, directory }) {
128
158
* @return {boolean } True for absolute uri
129
159
*/
130
160
function testIsAbsolute ( uri ) {
131
- return ! ! uri && ( typeof root === 'string' ) && loaderUtils . isUrlRequest ( uri , root ) &&
161
+ return ! ! uri && ( typeof root === 'string' ) && isUrlRequest ( uri , root ) &&
132
162
( / ^ \/ / . test ( uri ) || path . isAbsolute ( uri ) ) ;
133
163
}
134
164
}
0 commit comments