Skip to content

Commit 457cf68

Browse files
committed
fix srcset transform module not resovling alias path
1 parent 069bc31 commit 457cf68

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function urlToRequire (url) {
4747
if (firstChar === '.' || firstChar === '~') {
4848
if (firstChar === '~') {
4949
var secondChar = url.charAt(1)
50-
url = '"' + url.slice(secondChar === '/' ? 2 : 1)
50+
url = url.slice(secondChar === '/' ? 2 : 1)
5151
}
5252
return `require("${url}")`
5353
}

test/fixtures/transform.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55
<image xlink:href="./logo.png" />
66
</svg>
77
<img src="./logo.png" srcset="./logo.png 2x">
8+
<img src="./logo.png" srcset="~fixures/logo.png 2x">
89
<img src="./logo.png" srcset="./logo.png 2x, ./logo.png 3x">
10+
<img src="./logo.png" srcset="~fixures/logo.png 2x, ~fixures/logo.png 3x">
911
<img
1012
src="./logo.png"
1113
srcset="
1214
./logo.png 2x,
1315
./logo.png 3x
1416
">
17+
<img
18+
src="./logo.png"
19+
srcset="
20+
~fixures/logo.png 2x,
21+
~fixures/logo.png 3x
22+
">
1523
</div>
1624
</template>
1725

test/test.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,11 @@ describe('vue-loader', () => {
415415

416416
it('transformToRequire option', done => {
417417
test({
418+
resolve: {
419+
alias: {
420+
fixures: path.resolve(__dirname, 'fixtures')
421+
}
422+
},
418423
entry: './test/fixtures/transform.vue',
419424
module: {
420425
rules: [
@@ -440,10 +445,16 @@ describe('vue-loader', () => {
440445

441446
// image tag with srcset
442447
expect(vnode.children[4].data.attrs.srcset).to.equal(dataURL + ' 2x')
448+
// image tag with alias srcset
449+
expect(vnode.children[6].data.attrs.srcset).to.equal(dataURL + ' 2x')
443450
// image tag with srcset with two candidates
444-
expect(vnode.children[6].data.attrs.srcset).to.equal(dataURL + ' 2x, ' + dataURL + ' 3x')
445-
// image tag with multiline srcset
446451
expect(vnode.children[8].data.attrs.srcset).to.equal(dataURL + ' 2x, ' + dataURL + ' 3x')
452+
// image tag with alias srcset with two candidates
453+
expect(vnode.children[10].data.attrs.srcset).to.equal(dataURL + ' 2x, ' + dataURL + ' 3x')
454+
// image tag with multiline srcset
455+
expect(vnode.children[12].data.attrs.srcset).to.equal(dataURL + ' 2x, ' + dataURL + ' 3x')
456+
// image tag with alias multiline srcset
457+
expect(vnode.children[14].data.attrs.srcset).to.equal(dataURL + ' 2x, ' + dataURL + ' 3x')
447458

448459
// style
449460
expect(includeDataURL(style)).to.equal(true)

0 commit comments

Comments
 (0)