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 condition compiler #206

Open
wants to merge 5 commits 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
32 changes: 32 additions & 0 deletions docs/envs.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,38 @@ if (TARO_ENV === 'weapp') {

:::

### 组件文件中跨平台支持

为了方便大家书写样式跨端的组件代码,目前在.vue文件template模板内容中支持条件编译的特性。

指定平台保留样式:

```vue
/* #ifdef %PLATFORM% */
模板代码
/* #endif */
```

指定平台剔除样式:

```vue
/* #ifndef %PLATFORM% */
模板代码
/* #endif */
```

其中 `PLATFORM` 的取值与 `process.env.TARO_ENV` 保持一致

例如,希望某段模板内容只在 **微信小程序中** 生效,可以如下写法

```vue
/* #ifdef weapp */
模板代码
/* #endif */
```

如果是多个平台,之间可以使用 || 来分隔平台名称。

## 统一接口的多端文件

内置环境变量虽然可以解决大部分跨端的问题,但是会让代码中充斥着逻辑判断的代码,影响代码的可维护性,而且也让代码变得愈发丑陋。为了解决这种问题,Taro 提供了另外一种跨端开发的方式作为补充。
Expand Down
32 changes: 32 additions & 0 deletions versioned_docs/version-3.x/envs.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,38 @@ if (TARO_ENV === 'weapp') {

:::

### 组件文件中跨平台支持

为了方便大家书写样式跨端的组件代码,目前在.vue文件template模板内容中支持条件编译的特性。

指定平台保留样式:

```vue
/* #ifdef %PLATFORM% */
模板代码
/* #endif */
```

指定平台剔除样式:

```vue
/* #ifndef %PLATFORM% */
模板代码
/* #endif */
```

其中 `PLATFORM` 的取值与 `process.env.TARO_ENV` 保持一致

例如,希望某段模板内容只在 **微信小程序中** 生效,可以如下写法

```vue
/* #ifdef weapp */
模板代码
/* #endif */
```

如果是多个平台,之间可以使用 || 来分隔平台名称。

## 统一接口的多端文件

内置环境变量虽然可以解决大部分跨端的问题,但是会让代码中充斥着逻辑判断的代码,影响代码的可维护性,而且也让代码变得愈发丑陋。为了解决这种问题,Taro 提供了另外一种跨端开发的方式作为补充。
Expand Down