platform.macro
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

platform.macro

用于执行编译时平台环境判断 babel-plugin-macros

通过编译时环境变量 PLATFORM 判断, 将编译是时的引用 isWechat isWeb isToutiao 转换成 boolean 值, 构建出对应平台所需的代码(移除其他平台) 实现按需构建

安装

npm install platform.macro --save

示例

配合 babel-plugin-macros 插件使用

// input.js
import { isWecaht } from 'platform.macro';

if (isWechat) {
  // 小程序环境执行
  wx.showToast('我是小程序');
} else {
  window.alert('我是 web 环境');
}
$ PLATFORM=wechat babel input.js -o output.js
// output.js
'use strict';

// 小程序环境执行
wx.showToast('我是小程序');

Package Sidebar

Install

npm i platform.macro

Weekly Downloads

2

Version

2.0.0

License

MIT

Unpacked Size

3.97 kB

Total Files

4

Last publish

Collaborators

  • noyobo