Skip to content
Merged
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
4 changes: 3 additions & 1 deletion packages/hap-compiler/src/style/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function parse(source) {

let code = source.code || ''
const filePath = source.filePath
const cardEntry = source.cardEntry
const curDir = path.dirname(filePath)
// 引入的CSS文件列表
const depList = []
Expand Down Expand Up @@ -93,7 +94,8 @@ function parse(source) {
} else if (name === 'src') {
// 校验属性值
const subResult = validateDelaration('fontSrc', value, {
filePath
filePath,
cardEntry
})
if (subResult.log) {
log.push({
Expand Down
2 changes: 1 addition & 1 deletion packages/hap-compiler/src/style/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ const validator = {
let value = url[2]
if (!/^data:/.test(value) && !/^http(s)?:/.test(value)) {
// 转换为以项目源码为根的绝对路径
value = resolvePath(value, options.filePath)
value = resolvePath(value, options.filePath, options.cardEntry)
}
return { value: value }
}
Expand Down
18 changes: 13 additions & 5 deletions packages/hap-compiler/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,21 @@ export function isValidValue(value) {
* @returns {*}
* @desc 将文件相对路径转为项目根目录('src/')下的绝对路径
*/
export function resolvePath(relativePath, filePath, cardEntry = '') {
export function resolvePath(relativePath, filePath, cardEntry) {
if (filePath && !path.isAbsolute(relativePath)) {
const absolutePath = path.join(path.dirname(filePath), relativePath)
const relativeProjectPath = path.relative(
path.resolve(globalConfig.projectPath, './src', cardEntry),
absolutePath
)
let relativeProjectPath
if (cardEntry && filePath.indexOf('node_modules') > -1) {
relativeProjectPath = path.join(
cardEntry,
path.relative(globalConfig.projectPath, absolutePath)
)
} else {
relativeProjectPath = path.relative(
path.resolve(globalConfig.projectPath, './src'),
absolutePath
)
}
const newAbsolutePath = path.join('/', relativeProjectPath)
// 兼容windows
relativePath = newAbsolutePath.replace(/\\/g, '/')
Expand Down
1 change: 1 addition & 0 deletions packages/hap-dsl-xvm/src/loaders/style-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default function styleLoader(code) {
const resourcePath = this.resourcePath // 当前文件绝对路径

const { depList, log, depFiles, jsonStyle } = parseStyle({
cardEntry: options.cardEntry,
filePath: resourcePath,
code: code,
query: loaderQuery
Expand Down
3 changes: 2 additions & 1 deletion packages/hap-toolkit/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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

/**
* 关闭开发服务及停止webpack watching
Expand Down Expand Up @@ -65,6 +65,7 @@ export {
stopServer,
launchWithWatch,
stopAll,
killAdb,
BuildModeManager,
updateWebViewOptions
}
Loading