Skip to content

Commit b5a926f

Browse files
authored
fix: update static assets path for widgets (#108)
* fix: update static assets path for widgets Signed-off-by: lileirjyb <lileirjyb@vivo.com> * fix: add killAdb export Signed-off-by: lileirjyb <lileirjyb@vivo.com> --------- Signed-off-by: lileirjyb <lileirjyb@vivo.com>
1 parent 82c77c9 commit b5a926f

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

packages/hap-compiler/src/style/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function parse(source) {
3030

3131
let code = source.code || ''
3232
const filePath = source.filePath
33+
const cardEntry = source.cardEntry
3334
const curDir = path.dirname(filePath)
3435
// 引入的CSS文件列表
3536
const depList = []
@@ -93,7 +94,8 @@ function parse(source) {
9394
} else if (name === 'src') {
9495
// 校验属性值
9596
const subResult = validateDelaration('fontSrc', value, {
96-
filePath
97+
filePath,
98+
cardEntry
9799
})
98100
if (subResult.log) {
99101
log.push({

packages/hap-compiler/src/style/validator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ const validator = {
803803
let value = url[2]
804804
if (!/^data:/.test(value) && !/^http(s)?:/.test(value)) {
805805
// 转换为以项目源码为根的绝对路径
806-
value = resolvePath(value, options.filePath)
806+
value = resolvePath(value, options.filePath, options.cardEntry)
807807
}
808808
return { value: value }
809809
}

packages/hap-compiler/src/utils.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,21 @@ export function isValidValue(value) {
198198
* @returns {*}
199199
* @desc 将文件相对路径转为项目根目录('src/')下的绝对路径
200200
*/
201-
export function resolvePath(relativePath, filePath, cardEntry = '') {
201+
export function resolvePath(relativePath, filePath, cardEntry) {
202202
if (filePath && !path.isAbsolute(relativePath)) {
203203
const absolutePath = path.join(path.dirname(filePath), relativePath)
204-
const relativeProjectPath = path.relative(
205-
path.resolve(globalConfig.projectPath, './src', cardEntry),
206-
absolutePath
207-
)
204+
let relativeProjectPath
205+
if (cardEntry && filePath.indexOf('node_modules') > -1) {
206+
relativeProjectPath = path.join(
207+
cardEntry,
208+
path.relative(globalConfig.projectPath, absolutePath)
209+
)
210+
} else {
211+
relativeProjectPath = path.relative(
212+
path.resolve(globalConfig.projectPath, './src'),
213+
absolutePath
214+
)
215+
}
208216
const newAbsolutePath = path.join('/', relativeProjectPath)
209217
// 兼容windows
210218
relativePath = newAbsolutePath.replace(/\\/g, '/')

packages/hap-dsl-xvm/src/loaders/style-loader.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default function styleLoader(code) {
3737
const resourcePath = this.resourcePath // 当前文件绝对路径
3838

3939
const { depList, log, depFiles, jsonStyle } = parseStyle({
40+
cardEntry: options.cardEntry,
4041
filePath: resourcePath,
4142
code: code,
4243
query: loaderQuery

packages/hap-toolkit/src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { BuildModeManager } from '@hap-toolkit/shared-utils'
77
import { launchServer, stopServer, updateWebViewOptions } from '@hap-toolkit/server'
8-
import { compile, stopWatch } from './commands/compile'
8+
import { compile, stopWatch, killAdb } from './commands/compile'
99

1010
/**
1111
* 关闭开发服务及停止webpack watching
@@ -65,6 +65,7 @@ export {
6565
stopServer,
6666
launchWithWatch,
6767
stopAll,
68+
killAdb,
6869
BuildModeManager,
6970
updateWebViewOptions
7071
}

0 commit comments

Comments
 (0)