Skip to content

fix srcset transform module not resovling alias path #1038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/template-compiler/modules/transform-srcset.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function urlToRequire (url) {
if (firstChar === '.' || firstChar === '~') {
if (firstChar === '~') {
var secondChar = url.charAt(1)
url = '"' + url.slice(secondChar === '/' ? 2 : 1)
url = url.slice(secondChar === '/' ? 2 : 1)
}
return `require("${url}")`
}
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/transform.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@
<image xlink:href="./logo.png" />
</svg>
<img src="./logo.png" srcset="./logo.png 2x">
<img src="./logo.png" srcset="~fixures/logo.png 2x">
<img src="./logo.png" srcset="./logo.png 2x, ./logo.png 3x">
<img src="./logo.png" srcset="~fixures/logo.png 2x, ~fixures/logo.png 3x">
<img
src="./logo.png"
srcset="
./logo.png 2x,
./logo.png 3x
">
<img
src="./logo.png"
srcset="
~fixures/logo.png 2x,
~fixures/logo.png 3x
">
</div>
</template>

Expand Down
15 changes: 13 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,11 @@ describe('vue-loader', () => {

it('transformToRequire option', done => {
test({
resolve: {
alias: {
fixures: path.resolve(__dirname, 'fixtures')
}
},
entry: './test/fixtures/transform.vue',
module: {
rules: [
Expand All @@ -440,10 +445,16 @@ describe('vue-loader', () => {

// image tag with srcset
expect(vnode.children[4].data.attrs.srcset).to.equal(dataURL + ' 2x')
// image tag with alias srcset
expect(vnode.children[6].data.attrs.srcset).to.equal(dataURL + ' 2x')
// image tag with srcset with two candidates
expect(vnode.children[6].data.attrs.srcset).to.equal(dataURL + ' 2x, ' + dataURL + ' 3x')
// image tag with multiline srcset
expect(vnode.children[8].data.attrs.srcset).to.equal(dataURL + ' 2x, ' + dataURL + ' 3x')
// image tag with alias srcset with two candidates
expect(vnode.children[10].data.attrs.srcset).to.equal(dataURL + ' 2x, ' + dataURL + ' 3x')
// image tag with multiline srcset
expect(vnode.children[12].data.attrs.srcset).to.equal(dataURL + ' 2x, ' + dataURL + ' 3x')
// image tag with alias multiline srcset
expect(vnode.children[14].data.attrs.srcset).to.equal(dataURL + ' 2x, ' + dataURL + ' 3x')

// style
expect(includeDataURL(style)).to.equal(true)
Expand Down