Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wxs运行时压缩 #1791

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion packages/core/src/dynamic/vnode/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export default function _genVnodeTree (astData, contextScope, options) {
node.attrsList.forEach((attr) => {
if (attr.name === 'class' || attr.name === 'style') {
// class/style 的表达式为数组形式,class/style的计算过程需要放到逻辑层,主要是因为有逻辑匹配的过程去生成 vnodeTree
const helper = attr.name === 'class' ? stringify.stringifyClass : stringify.stringifyStyle
const helper = attr.name === 'class' ? stringify.c : stringify.s
let value = ''
if (attr.__exp) {
let valueArr = evalExps(attr.__exp)
Expand Down
4 changes: 2 additions & 2 deletions packages/webpack-plugin/lib/runtime/stringify.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,13 @@ function normalizeDynamicStyle (value) {
}

module.exports = {
stringifyClass: function (staticClass, dynamicClass) {
c: function (staticClass, dynamicClass) {
if (typeof staticClass !== 'string') {
return console.log('Template attr class must be a string!')
}
return concat(staticClass, mpEscape(stringifyDynamicClass(dynamicClass)))
},
stringifyStyle: function (staticStyle, dynamicStyle) {
s: function (staticStyle, dynamicStyle) {
var normalizedDynamicStyle = normalizeDynamicStyle(dynamicStyle)
var parsedStaticStyle = typeof staticStyle === 'string' ? parseStyleText(staticStyle) : {}
return genStyleText(extend(parsedStaticStyle, normalizedDynamicStyle))
Expand Down
6 changes: 3 additions & 3 deletions packages/webpack-plugin/lib/template-compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const i18nWxsLoaderPath = normalize.lib('wxs/i18n-loader.js')
const i18nWxsRequest = '~' + i18nWxsLoaderPath + '!' + i18nWxsPath
const i18nModuleName = '__i18n__'
const stringifyWxsPath = '~' + normalize.lib('runtime/stringify.wxs')
const stringifyModuleName = '__stringify__'
const stringifyModuleName = '__sm__'
const optionalChainWxsPath = '~' + normalize.lib('runtime/oc.wxs')
const optionalChainWxsName = '__oc__'

Expand Down Expand Up @@ -2133,7 +2133,7 @@ function processClass (el, meta) {
addAttrs(el, [{
name: targetType,
// swan中externalClass是通过编译时静态实现,因此需要保留原有的staticClass形式避免externalClass失效
value: mode === 'swan' && staticClass ? `${staticClass} {{${stringifyModuleName}.stringifyClass('', ${dynamicClassExp})}}` : `{{${stringifyModuleName}.stringifyClass(${staticClassExp}, ${dynamicClassExp})}}`
value: mode === 'swan' && staticClass ? `${staticClass} {{${stringifyModuleName}.c('', ${dynamicClassExp})}}` : `{{${stringifyModuleName}.c(${staticClassExp}, ${dynamicClassExp})}}`
}])
injectWxs(meta, stringifyModuleName, stringifyWxsPath)
} else if (staticClass) {
Expand Down Expand Up @@ -2166,7 +2166,7 @@ function processStyle (el, meta) {
const dynamicStyleExp = parseMustacheWithContext(dynamicStyle).result
addAttrs(el, [{
name: targetType,
value: `{{${stringifyModuleName}.stringifyStyle(${staticStyleExp}, ${dynamicStyleExp})}}`
value: `{{${stringifyModuleName}.s(${staticStyleExp}, ${dynamicStyleExp})}}`
}])
injectWxs(meta, stringifyModuleName, stringifyWxsPath)
} else if (staticStyle) {
Expand Down