diff --git a/packages/uni-cli-shared/lib/cache.js b/packages/uni-cli-shared/lib/cache.js
index 8241a0b93f5f0b83f08c017f8d7fd344f16f0b27..f8a2223416619807fe034e371afd49e782f8e695 100644
--- a/packages/uni-cli-shared/lib/cache.js
+++ b/packages/uni-cli-shared/lib/cache.js
@@ -231,8 +231,6 @@ function getSpecialMethods (name) {
return componentSpecialMethods[name] || []
}
-const pagesJsonPath = path.resolve(process.env.UNI_INPUT_DIR, 'pages.json')
-
const cacheTypes = ['babel-loader', 'css-loader', 'uni-template-compiler', 'vue-loader']
function clearCache () {
@@ -262,7 +260,8 @@ module.exports = {
// 先简单处理,该方案不好,
// 后续为 pages-loader 增加 cache-loader,
// 然后其他修改 json 的地方也要定制 cache-loader
- store () {
+ store () {
+ const pagesJsonPath = path.resolve(process.env.UNI_INPUT_DIR, 'pages.json')
const filepath = path.resolve(
process.env.UNI_CLI_CONTEXT,
'node_modules/.cache/uni-pages-loader/' + process.env.UNI_PLATFORM,
@@ -294,7 +293,8 @@ module.exports = {
clearCache()
} catch (e) {}
return
- }
+ }
+ const pagesJsonPath = path.resolve(process.env.UNI_INPUT_DIR, 'pages.json')
const mtimeMs = fs.statSync(pagesJsonPath).mtimeMs
const jsonCache = require(filepath)
if (jsonCache.mtimeMs !== mtimeMs) {
diff --git a/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js b/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
index 152920fa5e6273f6b8f41b62e554a5ea45de7123..adc8becf7fa3af12a6859c66d0f50c960f241827 100644
--- a/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.service.spec.js
@@ -71,6 +71,10 @@ describe('codegen', () => {
'{{ user.firstName }}',
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }){return [_v((_$s(0,'t0',_s(user.firstName))))]}}])})}`
)
+ assertCodegen(
+ 'ABCD',
+ `with(this){return _c('current-user',{attrs:{"_i":0}},[_v("")])}`
+ )
})
it('generate keep-alive', () => {
diff --git a/packages/uni-template-compiler/__tests__/demo.js b/packages/uni-template-compiler/__tests__/demo.js
index 564f9d4e4e0cf2af14456a1dabf75b93eccd764e..c6405790d987e5c608c34e76c695fc16834b92d6 100644
--- a/packages/uni-template-compiler/__tests__/demo.js
+++ b/packages/uni-template-compiler/__tests__/demo.js
@@ -1,7 +1,7 @@
const compiler = require('../lib')
const res = compiler.compile(
`
-
+ABCD
`, {
resourcePath: '/User/fxy/Documents/test.wxml',
isReservedTag: function (tag) {
@@ -14,8 +14,8 @@ const res = compiler.compile(
platform: 'app-plus'
},
filterModules: ['swipe'],
- // service: true,
- view: true
+ service: true
+ // view: true
})
console.log(require('util').inspect(res, {
diff --git a/packages/uni-template-compiler/lib/app/optimizer.js b/packages/uni-template-compiler/lib/app/optimizer.js
index 50d5d7d0f7b29db394d1f52e4dbc311ea77fa3fd..948dbea31332dcddb6612afb72716b88e625b652 100644
--- a/packages/uni-template-compiler/lib/app/optimizer.js
+++ b/packages/uni-template-compiler/lib/app/optimizer.js
@@ -43,6 +43,7 @@ function isStatic (node) {
function markStatic (node) {
if (isStatic(node)) { // 静态节点且仅包含 ID 属性
if (
+ node.attrs &&
node.attrs.length === 1 &&
!node.key &&
!node.ref &&
@@ -56,13 +57,17 @@ function markStatic (node) {
delete node.staticClass
delete node.staticStyle
- if (node.attrs && !isComponent(node.tag) && node.tag !== 'keep-alive') { // 移除静态属性
+ const isCustomComponent = isComponent(node.tag)
+ if (node.attrs && !isCustomComponent && node.tag !== 'keep-alive') { // 移除静态属性
node.attrs = node.attrs.filter(attr => attr.name === ID || isVar(attr.value))
}
node.children = node.children.filter(child => { // 移除静态文本
if (child.type === 3) { // ASTText
- return false
+ if (!isCustomComponent) {
+ return false
+ }
+ child.text = '' // slot ABCD
}
return true
})