Skip to content

Commit 9a4b7da

Browse files
committed
fix: fit for watch mode and add some comments
Signed-off-by: lileirjyb <[email protected]>
1 parent cf27357 commit 9a4b7da

File tree

7 files changed

+17
-9
lines changed

7 files changed

+17
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function processImport(csscode, dir, log, depList) {
141141
* @param {String} filePath - 文件路径
142142
* @param {Array} depFiles - 使用到的资源集合
143143
*/
144-
function processSingleClass(rule, jsonStyle, ruleResult, log, filePath, depFiles, options) {
144+
function processSingleClass(rule, jsonStyle, ruleResult, log, filePath, depFiles) {
145145
rule.declarations.forEach(function (declaration) {
146146
const subType = declaration.type
147147

packages/hap-packager/src/plugins/card-plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class CardPlugin {
7272
handledTemplateCardRes = postHandleJSCardRes(templateRes)
7373
}
7474

75-
// 用于修改 template 的 key 的 stringify 的顺序,type放第一个,children放最后一个
75+
// 用于修改 template 的 key 的 stringify 的顺序,type 放第一个,children 放最后一个
7676
let templateKeys = []
7777
recordKeys(handledTemplateCardRes, templateKeys)
7878

packages/hap-packager/src/plugins/card-script-handle-plugin.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ const PLUGIN_NAME = 'CardScriptHandlePlugin'
1212
const SUFFIX_UX = '.ux'
1313
const CARD_ENTRY = '#entry'
1414

15+
/**
16+
* 修改输出的 js 的内容:
17+
* 1. 增加 $json_require$方法,用于配合引擎读取 template.json 的内容
18+
* 2. style 通过 @info 来标记,用于配合引擎读取 css.json 的内容
19+
*/
1520
class CardScriptHandlePlugin {
1621
constructor(options = {}) {
1722
this.options = options || {}
@@ -163,6 +168,7 @@ class CardScriptHandlePlugin {
163168
}
164169
return relativeSrcPathStr
165170
}
171+
// 通过匹配__webpack_require__('xxxx')中的值来获取组件名
166172
getCompPath(str, pathSrc) {
167173
const regex = /__webpack_require__\("([^"]+)"\)/
168174
const match = str.match(regex)

packages/hap-packager/src/plugins/remove-modules-plugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class RemoveModulesPlugin {
1818

1919
apply(compiler) {
2020
compiler.hooks.compilation.tap('RemoveModulesPlugin', (compilation) => {
21-
// 在生成资源之前,遍历所有模块,删除 jscard 的 template 和 style 模块
21+
// 在生成资源之前,遍历所有模块,删除 jscard 的 template 和 style 模块,保证输出的 js 中不包含 template 和 style
2222
compilation.hooks.optimizeModules.tap('RemoveModulesPlugin', (modules) => {
2323
modules.forEach((module) => {
2424
const { _source, request } = module
@@ -35,7 +35,7 @@ class RemoveModulesPlugin {
3535
}
3636
})
3737
})
38-
// 在生成资源之前,遍历所有模块,删除 jscard 的 template 和 style 模块
38+
// 在生成资源之前,遍历所有模块,删除 jscard 的 template 和 style 模块,保证输出的 js 中不包含 template 和 style
3939
compilation.hooks.optimizeChunks.tap('RemoveModulesPlugin', (chunks) => {
4040
chunks.forEach((chunk) => {
4141
const chunkGraph = compilation.chunkGraph

packages/hap-packager/src/post-handler/js-card-post.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ function isSimpleArr(exp) {
280280
}
281281

282282
let res = true
283-
// 检查所有[]匹配项是否全部为数字
283+
// 检查所有[]匹配项是否全部为数字或常量字符串
284284
results.forEach((content) => {
285-
if (!/^\d+$/.test(content)) {
285+
if (!/^\d+$/.test(content) && !/^('|")(.*)\1$/.test(content)) {
286286
res = false
287287
}
288288
})

packages/hap-toolkit/src/gen-webpack-conf/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ export default async function genWebpackConf(launchOptions, mode) {
193193
globalConfig.isSmartMode =
194194
compileOptionsObject.splitChunksMode === compileOptionsMeta.splitChunksModeEnum.SMART
195195

196+
// JS 卡由于将js assets中template和style抽取出来,如果使用缓存会编译错误。故卡片不使用缓存。
197+
const isCard = Object.values(entries).some((entry) => entry.indexOf('card=1') > -1)
196198
let cache =
197-
isJest ||
199+
(isJest ||
198200
isProduction ||
199201
compileOptionsObject.disableCache ||
200202
// 提取公共 css 时不支持使用缓存,toolkit 内部的 cssModule 不支持缓存
@@ -210,7 +212,7 @@ export default async function genWebpackConf(launchOptions, mode) {
210212
config: [__filename, path.resolve(__dirname, '../../package.json')]
211213
},
212214
version: TOOLKIT_VERSION + ''
213-
}
215+
}) && !isCard
214216

215217
const webpackConf = {
216218
context: cwd,

packages/hap-toolkit/src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export function resolveEntries(manifest, basedir, cwd) {
108108
sourceFile = './' + sourceFile + `?uxType=${type}`
109109
sourceFile = sourceFile.replace(/\\/g, '/')
110110
if (type === ENTRY_TYPE.CARD) {
111-
sourceFile += '&card=1' // lite card
111+
sourceFile += '&card=1' // card
112112
if (conf.type === 'lite') {
113113
sourceFile += '&lite=1' // lite card
114114
}

0 commit comments

Comments
 (0)