From 2fa7cd5dbaed700a70f1b6692ed2849799054b6a Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Mon, 9 Mar 2020 20:04:31 +0800 Subject: [PATCH] feat(qa): view=>div --- packages/uni-quickapp/lib/chain-webpack.js | 1 + packages/uni-quickapp/lib/compiler-module.js | 7 +++++++ packages/uni-template-compiler/lib/index.js | 5 ++++- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 packages/uni-quickapp/lib/compiler-module.js diff --git a/packages/uni-quickapp/lib/chain-webpack.js b/packages/uni-quickapp/lib/chain-webpack.js index 37c4cea5..d6634407 100644 --- a/packages/uni-quickapp/lib/chain-webpack.js +++ b/packages/uni-quickapp/lib/chain-webpack.js @@ -8,6 +8,7 @@ module.exports = config => { .tap(options => Object.assign(options, { compiler: require('@dcloudio/uni-template-compiler'), compilerOptions: { + quickapp: true, preserveWhitespace: false }, hotReload: false, diff --git a/packages/uni-quickapp/lib/compiler-module.js b/packages/uni-quickapp/lib/compiler-module.js new file mode 100644 index 00000000..fde52755 --- /dev/null +++ b/packages/uni-quickapp/lib/compiler-module.js @@ -0,0 +1,7 @@ +module.exports = { + preTransformNode(el) { + if (el.tag === 'view') { // view 是最常用组件,直接映射为div标签,保证性能 + el.tag = 'div' + } + } +} diff --git a/packages/uni-template-compiler/lib/index.js b/packages/uni-template-compiler/lib/index.js index ff13c3db..925dc967 100644 --- a/packages/uni-template-compiler/lib/index.js +++ b/packages/uni-template-compiler/lib/index.js @@ -72,9 +72,12 @@ module.exports = { console.error(source) throw e } + } else if (options.quickapp) { + // 后续改版,应统一由具体包实现 + (options.modules || (options.modules = [])).push(require('@dcloudio/uni-quickapp/lib/compiler-module')) } - if (!options.mp) { // h5 + if (!options.mp) { // h5,quickapp return compileTemplate(source, options, compile) } -- GitLab