Skip to content

Commit c48b6c7

Browse files
pi0yyx990803
authored andcommitted
fix(transform-require): support ~/ aliases (#927)
* fix(transform-require): support ~/ aliases * test: add tests for ~/ aliases
1 parent 1172384 commit c48b6c7

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ function rewrite (attr, name) {
4040
var firstChar = value.charAt(1)
4141
if (firstChar === '.' || firstChar === '~') {
4242
if (firstChar === '~') {
43-
value = '"' + value.slice(2)
43+
var secondChar = value.charAt(2)
44+
value = '"' + value.slice(secondChar === '/' ? 3 : 2)
4445
}
4546
attr.value = `require(${value})`
4647
}

test/fixtures/resolve.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
<div>
33
<img src="./logo.png">
44
<img src="~fixtures/logo.png">
5+
<img src="~/fixtures/logo.png">
56
</div>
67
</template>
78

89
<style>
910
html { background-image: url(./logo.png); }
1011
body { background-image: url(~fixtures/logo.png); }
12+
body { background-image: url(~/fixtures/logo.png); }
1113
</style>

0 commit comments

Comments
 (0)