babel-preset-taro 3.4.0 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +1 -1
  2. package/package.json +6 -7
  3. package/rn/index.js +19 -12
package/index.js CHANGED
@@ -28,7 +28,7 @@ module.exports = (_, options = {}) => {
28
28
  }])
29
29
  if (process.env.TARO_ENV === 'h5' && process.env.NODE_ENV !== 'production' && options.hot !== false) {
30
30
  if (options.framework === 'react') {
31
- plugins.push([require('react-refresh/babel')])
31
+ plugins.push([require('react-refresh/babel'), { skipEnvCheck: true }])
32
32
  } else if (options.framework === 'preact') {
33
33
  overrides.push({
34
34
  include: /\.[jt]sx$/,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-preset-taro",
3
- "version": "3.4.0",
3
+ "version": "3.4.1",
4
4
  "description": "> TODO: description",
5
5
  "author": "yuche <i@yuche.me>",
6
6
  "homepage": "https://github.com/nervjs/taro/tree/master/packages/babel-preset-taro#readme",
@@ -36,20 +36,19 @@
36
36
  "@babel/runtime": "^7.14.5",
37
37
  "@babel/runtime-corejs3": "^7.14.5",
38
38
  "@prefresh/babel-plugin": "^0.4.1",
39
- "@tarojs/helper": "3.4.0",
40
- "@tarojs/taro-h5": "3.4.0",
41
- "@tarojs/taro-rn": "3.4.0",
39
+ "@tarojs/helper": "3.4.1",
40
+ "@tarojs/taro-h5": "3.4.1",
42
41
  "@vue/babel-plugin-jsx": "^1.0.6",
43
42
  "@vue/babel-preset-jsx": "^1.2.4",
44
43
  "babel-plugin-dynamic-import-node": "2.3.3",
45
44
  "babel-plugin-global-define": "1.0.3",
46
45
  "babel-plugin-jsx-attributes-array-to-object": "0.3.0",
47
46
  "babel-plugin-transform-imports-api": "1.0.0",
48
- "babel-plugin-transform-react-jsx-to-rn-stylesheet": "3.4.0",
49
- "babel-plugin-transform-taroapi": "3.4.0",
47
+ "babel-plugin-transform-react-jsx-to-rn-stylesheet": "3.4.1",
48
+ "babel-plugin-transform-taroapi": "3.4.1",
50
49
  "core-js": "^3.6.5",
51
50
  "metro-react-native-babel-preset": "^0.66.2",
52
51
  "react-refresh": "0.9.0"
53
52
  },
54
- "gitHead": "a0e97bc937f878cc059f54748c9a3829fa3f4664"
53
+ "gitHead": "a2437215b1966fd0b6dd09311bcb4fd894a871d0"
55
54
  }
package/rn/index.js CHANGED
@@ -60,14 +60,16 @@ function getEnv () {
60
60
  }
61
61
 
62
62
  function parseDefineConst (config) {
63
+ const result = {}
63
64
  Object.keys(config.defineConstants).forEach((key) => {
64
65
  try {
65
- config.defineConstants[key] = JSON.parse(config.defineConstants[key])
66
+ result[key] = JSON.parse(config.defineConstants[key])
66
67
  } catch (e) {
67
- console.error('defineConstants环境配置有误')
68
- config.defineConstants[key] = ''
68
+ console.error('defineConstants error: ', e)
69
+ result[key] = ''
69
70
  }
70
71
  })
72
+ return result
71
73
  }
72
74
 
73
75
  /**
@@ -77,17 +79,20 @@ function parseDefineConst (config) {
77
79
  function getDefineConstants () {
78
80
  const config = getProjectConfig()
79
81
  const rnconfig = getRNConfig()
82
+ const env = getEnv()
80
83
  if (rnconfig.defineConstants) {
81
- parseDefineConst(rnconfig)
82
- rnconfig.defineConstants = Object.assign(rnconfig.defineConstants, getEnv())
83
- return rnconfig.defineConstants
84
+ return {
85
+ ...parseDefineConst(rnconfig),
86
+ ...env
87
+ }
84
88
  }
85
89
  if (config.defineConstants) {
86
- parseDefineConst(config)
87
- config.defineConstants = Object.assign(config.defineConstants, getEnv())
88
- return config.defineConstants
90
+ return {
91
+ ...parseDefineConst(config),
92
+ ...env
93
+ }
89
94
  }
90
- return getEnv()
95
+ return env
91
96
  }
92
97
 
93
98
  function getCSSModule () {
@@ -112,7 +117,6 @@ module.exports = (_, options = {}) => {
112
117
  const nativeLibs = require('@tarojs/taro-rn/libList.js')
113
118
  const nativeInterfaces = nativeApis.concat(nativeLibs)
114
119
 
115
- getEnv()
116
120
  const defineConstants = getDefineConstants()
117
121
  const presets = []
118
122
  const plugins = []
@@ -155,13 +159,16 @@ module.exports = (_, options = {}) => {
155
159
  [require('babel-plugin-global-define'), defineConstants]
156
160
  )
157
161
 
158
- // 添加一个默认 plugin, 与小程序/h5保持一致. todo: 3.1后采用拓展的方式
162
+ // 添加一个默认 plugin, 与小程序/h5保持一致.
159
163
  plugins.push(
160
164
  [require('@babel/plugin-proposal-decorators'), {
161
165
  decoratorsBeforeExport,
162
166
  legacy: decoratorsLegacy !== false
163
167
  }]
164
168
  )
169
+
170
+ plugins.push(require('../remove-define-config'))
171
+
165
172
  return {
166
173
  presets,
167
174
  plugins