xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Taro ENV & NODE_ENV & process.env All In One

Taro ENV & NODE_ENV & process.env All In One

https://github.com/NervJS/taro-ui/blob/dev/src/common/utils.ts#L205

Taro.getEnv & Taro.ENV_TYPE


import Taro from '@tarojs/taro'
import { execObject, SelectorQuery } from '@tarojs/taro/types/index'

const ENV = Taro.getEnv()

function delay(delayTime = 500): Promise<null> {
  return new Promise(resolve => {
    if ([Taro.ENV_TYPE.WEB, Taro.ENV_TYPE.SWAN].includes(ENV)) {
      setTimeout(() => {
        resolve()
      }, delayTime)
      return
    }
    resolve()
  })
}


process.env.TARO_ENV

https://nervjs.github.io/taro/docs/envs.html#processenvtaro_env

// 如想在微信小程序和 H5 端分别引用不同资源

if (process.env.TARO_ENV === 'weapp') {
  require('path/to/weapp/name')
} else if (process.env.TARO_ENV === 'h5') {
  require('path/to/h5/name')
}


// 同时也可以在 JSX 中使用,决定不同端要加载的组件

render () {
  return (
    <View>
      {process.env.TARO_ENV === 'weapp' && <ScrollViewWeapp />}
      {process.env.TARO_ENV === 'h5' && <ScrollViewH5 />}
    </View>
  )
}


node env

https://nervjs.github.io/taro/docs/config-detail.html#env

process.env.NODE_ENV


webpack mode

https://webpack.js.org/configuration/mode/

process.env.NODE_ENV

If not set, webpack sets production as the default value for mode.

# string = 'production': 'none' | 'development' | 'production'
$ webpack --mode=none
$ webpack --mode=development
$ webpack --mode=production

process.env.NODE_ENV

$ process.env.NODE_ENV=production && webpack
$ process.env.NODE_ENV=development && webpack

https://github.com/xgqfrms-GitHub/Node-CLI-Tools/issues/13

linux & mac

$ export NODE_ENV=production

windows

$ set NODE_ENV=production

refs



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2020-04-02 22:51  xgqfrms  阅读(1747)  评论(4编辑  收藏  举报