File tree 2 files changed +11
-1
lines changed
2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ const isDynamicSrc = (src) => /\{\{/.test(src);
15
15
16
16
const isStartsWithDot = ( src ) => / ^ \. / . test ( src ) ;
17
17
18
+ const hasProcotol = ( src ) => / ^ ( \w + : ) ? \/ \/ / . test ( src ) ;
19
+
18
20
const replaceAt = ( str , start , end , replacement ) =>
19
21
str . slice ( 0 , start ) + replacement + str . slice ( end ) ;
20
22
@@ -121,7 +123,7 @@ export default function (content) {
121
123
const module = await loadModule ( request ) ;
122
124
let source = extract ( module , publicPath ) ;
123
125
const isSourceAbsolute = isAbsolute ( source ) ;
124
- if ( ! isSourceAbsolute ) {
126
+ if ( ! isSourceAbsolute && ! hasProcotol ( source ) ) {
125
127
source = ensureStartsWithDot ( source ) ;
126
128
}
127
129
if ( enforceRelativePath && isSourceAbsolute ) {
Original file line number Diff line number Diff line change @@ -153,4 +153,12 @@ describe('wxml-loader', () => {
153
153
await compile ( code , { enforceRelativePath : true } ) ;
154
154
expect ( getCompiledRes ( ) ) . toBe ( '<image src="./images/image.gif" />' ) ;
155
155
} ) ;
156
+
157
+ test ( 'should work if publicPath starts with protocol' , async ( ) => {
158
+ const code = '<image src="./fixture.gif" />' ;
159
+ await compile ( code , { globalPublicPath : 'http://m.baidu.com/' } ) ;
160
+ expect ( getCompiledRes ( ) ) . toBe (
161
+ '<image src="http://m.baidu.com/fixture.gif" />' ,
162
+ ) ;
163
+ } ) ;
156
164
} ) ;
You can’t perform that action at this time.
0 commit comments