Skip to content

Commit

Permalink
fix(cli): h5 端编译对于带有后缀的资源引用编译错误
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Jan 6, 2019
1 parent 3b77193 commit a96c994
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/taro-cli/src/h5.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,11 @@ function processEntry (code, filePath) {
if (pathArr.indexOf('pages') >= 0) {
astPath.remove()
} else if (Util.REG_SCRIPTS.test(value)) {
/* TODO windows下路径处理可能有问题 ../../lib/utils.js */
const dirname = path.dirname(value)
const extname = path.extname(value)
node.source = t.stringLiteral(path.join(dirname, path.basename(value, extname)).replace(/\\/g, '/'))
const realPath = path.resolve(filePath, '..', value)
const dirname = path.dirname(realPath)
const extname = path.extname(realPath)
const removeExtPath = path.join(dirname, path.basename(realPath, extname))
node.source = t.stringLiteral(Util.promoteRelativePath(path.relative(filePath, removeExtPath)).replace(/\\/g, '/'))
}
}
return
Expand Down Expand Up @@ -654,9 +655,11 @@ function processOthers (code, filePath, fileType) {
}
if (!Util.isNpmPkg(value)) {
if (Util.REG_SCRIPTS.test(value)) {
const dirname = path.dirname(value)
const extname = path.extname(value)
node.source = t.stringLiteral(path.join(dirname, path.basename(value, extname)).replace(/\\/g, '/'))
const realPath = path.resolve(filePath, '..', value)
const dirname = path.dirname(realPath)
const extname = path.extname(realPath)
const removeExtPath = path.join(dirname, path.basename(realPath, extname))
node.source = t.stringLiteral(Util.promoteRelativePath(path.relative(filePath, removeExtPath)).replace(/\\/g, '/'))
}
} else if (value === PACKAGES['@tarojs/taro']) {
let specifier = specifiers.find(item => item.type === 'ImportDefaultSpecifier')
Expand Down

0 comments on commit a96c994

Please sign in to comment.