Skip to content

Commit cf27357

Browse files
committed
fix: adapt for enable-extract-css option and fix for litecard h5 render in ide
Signed-off-by: lileirjyb <[email protected]>
1 parent f14c275 commit cf27357

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const componentId = (() => {
3030

3131
export default function styleLoader(code) {
3232
const self = this
33+
const options = loaderUtils.parseQuery(this.resourceQuery)
3334
const loaderQuery = loaderUtils.parseQuery(this.query)
3435
const suppresslogs = !!getWebpackOptions(this).suppresslogs
3536
const resourcePath = this.resourcePath // 当前文件绝对路径
@@ -40,7 +41,7 @@ export default function styleLoader(code) {
4041
query: loaderQuery
4142
})
4243

43-
if (compileOptionsObject.enableExtractCss) {
44+
if (compileOptionsObject.enableExtractCss && !options.card) {
4445
componentId.add(resourcePath)
4546
if (jsonStyle) {
4647
jsonStyle[`@info`] = {

packages/hap-dsl-xvm/src/loaders/ux-fragment-utils.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const defaultLoaders = {
5151
* @param uxType
5252
* @returns {*}
5353
*/
54-
function makeLoaderString(type, config, uxType) {
54+
function makeLoaderString(type, config, isCard, uxType) {
5555
config = config || {}
5656
let loaders
5757

@@ -146,10 +146,11 @@ function makeLoaderString(type, config, uxType) {
146146
}
147147
]
148148

149-
compileOptionsObject.enableExtractCss &&
149+
if (compileOptionsObject.enableExtractCss && !isCard) {
150150
loaders.unshift({
151151
name: defaultLoaders['extract-css']
152152
})
153+
}
153154

154155
let lang = config.lang
155156
if (lang && lang !== 'css') {
@@ -307,7 +308,7 @@ function processImportFrag($loader, imports, importNames, card, lite) {
307308
})
308309
let reqStr = makeRequireString(
309310
$loader,
310-
makeLoaderString(FRAG_TYPE.IMPORT),
311+
makeLoaderString(FRAG_TYPE.IMPORT, null, card),
311312
`${importSrc}?uxType=${ENTRY_TYPE.COMP}&name=${importName}${cardParam}${liteParam}`
312313
)
313314

@@ -353,9 +354,13 @@ function processTemplateFrag($loader, templates, uxType, importNames, card, lite
353354
importNames = importNames.map((item) => 'importNames[]=' + item)
354355
retStr = makeRequireString(
355356
$loader,
356-
makeLoaderString(FRAG_TYPE.TEMPLATE, {
357-
alone: !!fragAttrsSrc
358-
}),
357+
makeLoaderString(
358+
FRAG_TYPE.TEMPLATE,
359+
{
360+
alone: !!fragAttrsSrc
361+
},
362+
card
363+
),
359364
`${src}?uxType=${uxType}&${importNames.join(',')}${cardParam}${liteParam}${pathParam}`
360365
)
361366
}
@@ -391,10 +396,14 @@ function processStyleFrag($loader, styles, uxType, card, lite) {
391396
const pathParam = card ? `&uxPath=${src}` : ''
392397
code = makeRequireString(
393398
$loader,
394-
makeLoaderString(FRAG_TYPE.STYLE, {
395-
alone: !!fragAttrsSrc,
396-
lang: fragAttrsLang
397-
}),
399+
makeLoaderString(
400+
FRAG_TYPE.STYLE,
401+
{
402+
alone: !!fragAttrsSrc,
403+
lang: fragAttrsLang
404+
},
405+
card
406+
),
398407
`${src}?uxType=${uxType}${cardParam}${liteParam}${pathParam}`
399408
)
400409
}
@@ -408,7 +417,7 @@ function processStyleFrag($loader, styles, uxType, card, lite) {
408417
* @param uxType
409418
* @returns {string}
410419
*/
411-
function processScriptFrag($loader, scripts, uxType) {
420+
function processScriptFrag($loader, scripts, uxType, card) {
412421
let code = 'null'
413422
if (scripts.length) {
414423
// 有且仅有一个<script>节点
@@ -427,6 +436,7 @@ function processScriptFrag($loader, scripts, uxType) {
427436
alone: !!fragAttrsSrc,
428437
path: $loader.resourcePath
429438
},
439+
card,
430440
uxType
431441
),
432442
`${src}?uxType=${uxType}`
@@ -455,7 +465,7 @@ function processDataFrag($loader, datas, uxType) {
455465
}
456466
code = makeRequireString(
457467
$loader,
458-
makeLoaderString(FRAG_TYPE.DATA, {}, uxType),
468+
makeLoaderString(FRAG_TYPE.DATA, {}, true, uxType),
459469
`${src}?index=0&lite=1`
460470
)
461471
}
@@ -482,7 +492,7 @@ function processActionFrag($loader, datas, uxType) {
482492
}
483493
code = makeRequireString(
484494
$loader,
485-
makeLoaderString(FRAG_TYPE.ACTIONS, {}, uxType),
495+
makeLoaderString(FRAG_TYPE.ACTIONS, {}, true, uxType),
486496
`${src}?index=0&lite=1`
487497
)
488498
}
@@ -509,7 +519,7 @@ function processPropsFrag($loader, datas, uxType) {
509519
}
510520
code = makeRequireString(
511521
$loader,
512-
makeLoaderString(FRAG_TYPE.PROPS, {}, uxType),
522+
makeLoaderString(FRAG_TYPE.PROPS, {}, true, uxType),
513523
`${src}?index=0&lite=1`
514524
)
515525
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function assemble($loader, frags, name, uxType, card, lite) {
5656
let content = `${importFrag}\n`
5757
if (!lite) {
5858
// process script for JS card
59-
content += `var $app_script$ = ${processScriptFrag($loader, frags.script, uxType)}\n`
59+
content += `var $app_script$ = ${processScriptFrag($loader, frags.script, uxType, card)}\n`
6060
}
6161
content +=
6262
`$app_define$('@app-component/${name}', [], function($app_require$, $app_exports$, $app_module$) {\n` +

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class RemoveModulesPlugin {
2222
compilation.hooks.optimizeModules.tap('RemoveModulesPlugin', (modules) => {
2323
modules.forEach((module) => {
2424
const { _source, request } = module
25-
if (this.isCardAndCardcomp(request)) {
25+
if (this.isJsCardAndCardcomp(request)) {
2626
const { _valueAsString, _valueAsBuffer } = _source || {}
2727
const moduleSource = _valueAsString || _valueAsBuffer?.toString() || ''
2828
const type = this.getRequestType(request)
@@ -44,7 +44,7 @@ class RemoveModulesPlugin {
4444

4545
chunkModules.forEach((module) => {
4646
const { request } = module
47-
if (this.isCardAndCardcomp(request)) {
47+
if (this.isJsCardAndCardcomp(request)) {
4848
const type = this.getRequestType(request)
4949
const typeArr = LOADER_INFO_LIST.map((item) => item.type)
5050
if (
@@ -87,14 +87,15 @@ class RemoveModulesPlugin {
8787
})
8888
}
8989
// chunk.entryModule.rawRequest: ./src/cards/card/index.ux?uxType=card&card=1&lite=1
90-
isCardAndCardcomp(requestPath) {
90+
isJsCardAndCardcomp(requestPath) {
9191
if (requestPath && requestPath.lastIndexOf('?') > 0) {
9292
const pathParamIndex = requestPath.lastIndexOf('?')
9393
const paramStr = requestPath.substring(pathParamIndex + 1)
9494
const paramArr = paramStr.split('&')
9595
return (
9696
paramArr &&
9797
paramArr.indexOf('card=1') >= 0 &&
98+
paramArr.indexOf('lite=1') < 0 &&
9899
(paramArr.indexOf('uxType=card') >= 0 || paramArr.indexOf('uxType=comp') >= 0)
99100
)
100101
}

0 commit comments

Comments
 (0)