Skip to content

Commit 177194f

Browse files
committed
fix: 图片路径解析错误的问题
1 parent 79048a6 commit 177194f

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ module.exports = (userOptions, fileOptions) => {
2222
}
2323
}
2424

25+
function getPathBaseOnSrc (a, b) {
26+
return relative(a, b).replace(/^src\//, '')
27+
}
28+
2529
function transform (node, options, fileOptions) {
2630
for (var tag in options) {
2731
if (node.tag === tag && node.attrs) {
@@ -43,9 +47,9 @@ function rewrite (attrsMap, name, fileOptions) {
4347
var { resourcePath, outputPath, context } = fileOptions
4448
var assetPath = path.resolve(resourcePath, '..', value)
4549
// 资源路径, 为了分包,去掉了 src 目录
46-
var toPath = relative(context, assetPath).replace(/^\/src\//, '')
47-
attrsMap[name] = path.join(outputPath, toPath)
48-
copyAsset(assetPath, attrsMap[name])
50+
var toPath = getPathBaseOnSrc(context, assetPath)
51+
attrsMap[name] = relative(getPathBaseOnSrc(context, resourcePath), getPathBaseOnSrc(context, assetPath))
52+
copyAsset(assetPath, path.join(outputPath, toPath))
4953
}
5054
}
5155
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mpvue-loader",
3-
"version": "1.1.1",
3+
"version": "1.1.2-rc.2",
44
"description": "mpvue single-file component loader for Webpack",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)