babel-plugin-conditional-compile-with-comment
v1.0.2
Published
babel babel-plugin conditional-compile
Downloads
7
Maintainers
Readme
babel-plugin-conditional-compile
Overview
A Babel plugin for conditional compilation.
Install
To install the plugin, run the following command:
npm install --save-dev babel-plugin-conditional-compile
Or, if you're using Yarn:
yarn add --dev babel-plugin-conditional-compile
Usage
Configuration
Add the plugin to your Babel configuration file (e.g., .babelrc
or babel.config.js
). Specify the environment variable name that will trigger conditional compilation.
.babelrc (or babel.config.js)
{
"plugins": [
["conditional-compile-with-comment", {
"targetPlat": "WX" // 配置当前编译的目标平台是微信
}]
]
}
Coding with Conditional Compilation
In your JavaScript files, you can use special comments to mark code blocks for conditional compilation.
// ifdef targetPlat=watch-os|WX
console.log("When the configuration parameter targetPlat of the plugin is set to WX or watch-os, this piece of code will be retained during the compilation phase.");
// endif
// ifndef targetPlat=TT|DD
console.log("When the configuration parameter targetPlat of the plugin is set to DD or TT, this piece of code will be excluded during the compilation phase.");
// endif