Skip to content

Commit bcd54d2

Browse files
committed
fix: fix srcset transform for absolute urls (fix #1005)
1 parent 405a7c4 commit bcd54d2

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lib/template-compiler/modules/transform-srcset.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// vue compiler module for transforming `img:srcset` to a number of `require`s
22

3-
module.exports = function () {
4-
return {
5-
postTransformNode: node => {
6-
transform(node)
7-
}
3+
module.exports = () => ({
4+
postTransformNode: node => {
5+
transform(node)
86
}
9-
}
7+
})
108

119
function transform (node) {
1210
const tags = ['img', 'source']
@@ -15,8 +13,8 @@ function transform (node) {
1513
node.attrs.forEach(attr => {
1614
if (attr.name === 'srcset') {
1715
// same logic as in transform-require.js
18-
var value = attr.value
19-
var isStatic = value.charAt(0) === '"' && value.charAt(value.length - 1) === '"'
16+
const value = attr.value
17+
const isStatic = value.charAt(0) === '"' && value.charAt(value.length - 1) === '"'
2018
if (!isStatic) {
2119
return
2220
}
@@ -43,12 +41,14 @@ function transform (node) {
4341

4442
function urlToRequire (url) {
4543
// same logic as in transform-require.js
46-
var firstChar = url.charAt(0)
44+
const firstChar = url.charAt(0)
4745
if (firstChar === '.' || firstChar === '~') {
4846
if (firstChar === '~') {
49-
var secondChar = url.charAt(1)
50-
url = '"' + url.slice(secondChar === '/' ? 2 : 1)
47+
const secondChar = url.charAt(1)
48+
url = url.slice(secondChar === '/' ? 2 : 1)
5149
}
5250
return `require("${url}")`
51+
} else {
52+
return `"${url}"`
5353
}
5454
}

0 commit comments

Comments
 (0)