Skip to content

扩展自定义平台后,样式条件编译不生效 #341

Description

@parkerisme

taro4.0.8+webpack5环境下:
扩展自定义平台android,为什么继承TaroPlatformWeb ,因为android是基于webview开发,参考文档 :
class Android extends TaroPlatformWeb {
platform='android'
modifyWebpackChain() {
// 通过 this.ctx.modifyWepackChain 能获取到 WebpackChain 实例
this.ctx.modifyWebpackChain(({ chain }) => {
// chain.xxxx
})
}
}
使用命令打包:"lib:android": "taro build native-components --type android",
源码中样式:

<style scoped> /* 样式条件编译仍然可以使用 */ /* #ifdef android */ .android-specific { color: #33b5e5; } /* #endif */ /* #ifdef h5 */ .h5-specific { color: #33b5e5; } /* #endif */ </style>

打包后:
#ifdef android /
/
#endif /
/
#ifdef h5 /
.h5-specific[data-v-e326dcb2] {
color: #33b5e5;
}
/
#endif
android的样式没保留,反而保留了h5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions