Cross-Platform
Supported Platforms
Goji currently support these platforms. Each target has a target
name.
Platform | target |
---|---|
WeChat Mini Program | wechat |
Baidu Smart Program | baidu |
Alipay Mini Program | alipay |
Toutiao Micro App | toutiao |
QQ Mini Program | qq |
Conditions in JavaScript code
The current target can be checked by process.env.TARGET
in JavaScript code. This example shows how
it works.
switch (process.env.TARGET) {
case 'wechat':
return 'Hello, WeChat!';
case 'baidu':
return 'Hello, Baidu!';
// ...
default:
return 'Unknown';
}
You should always use
process.env.TARGET
as a whole. Don't reassignprocess
orprocess.env
to another variable.
Conditions in config code
Only .config.js
config file support conditions check of the target.
modele.exports = ({ target }) => {
if (target === 'alipay') {
return {
defaultTitle: '预订详情',
};
} else {
return {
navigationBarTitleText: '预订详情',
};
}
};
[Proposal] Wrong config file may cause warning in some platforms. For example, if you use Alipay's filed
defaultTitle
in WeChat Mini Program you may see this warning. To fix this issue we can use implement a new package@goji/config-generator
which can auto adjust the config files for different platforms.