feat(taro-plugin-vue3): sfc template conditional compilation #11482
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
这个 PR 做了什么? (简要描述所做更改)
使用 vue 3.0 单文件组件模板语法时,无法通过
v-if
判断process.env.TARO_ENV
来时实现条件编译。例如,
<view v-if="process.env.TARO_ENV==='weapp'"/>
会被编译为:这并不能删除不相关平台的代码。
本 PR 引入了一个编译时 tag 属性
taro-env
或taroEnv
, 其取值应与process.env.TARO_ENV
完全一致。在
@vue/sfc-compiler
对模板进行编译的过程中,通过比较taro-env
和process.env.TARO_ENV
的值来删除无关平台的节点, 从而实现 vue3 模板的条件编译。用法
yarn dev:weapp
编译后的结果为:<view>weapp 平台节点</view>
。yarn dev:h5
编译后的结果为:<view>h5 平台节点</view>
。此外本 PR 还将 h5 平台和小程序平台用到的
nodeTransform
函数都放到了一个文件里面。这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台: