babel-preset-taro 3.6.11 → 3.6.12

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 (2) hide show
  1. package/package.json +3 -6
  2. package/rn/index.js +0 -122
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-preset-taro",
3
- "version": "3.6.11",
3
+ "version": "3.6.12",
4
4
  "description": "Taro babel preset",
5
5
  "author": "yuche <i@yuche.me>",
6
6
  "homepage": "https://github.com/nervjs/taro/tree/master/packages/babel-preset-taro#readme",
@@ -29,17 +29,14 @@
29
29
  "@babel/runtime": "^7.14.5",
30
30
  "@babel/runtime-corejs3": "^7.14.5",
31
31
  "babel-plugin-dynamic-import-node": "2.3.3",
32
- "babel-plugin-global-define": "1.0.3",
33
- "babel-plugin-jsx-attributes-array-to-object": "0.3.0",
34
32
  "babel-plugin-minify-dead-code-elimination": "^0.5.2",
35
33
  "babel-plugin-transform-imports-api": "1.0.0",
36
34
  "core-js": "^3.6.5",
37
35
  "lodash": "^4.17.21",
38
36
  "metro-react-native-babel-preset": "^0.72.1",
39
37
  "react-refresh": "^0.11.0",
40
- "@tarojs/helper": "3.6.11",
41
- "@tarojs/shared": "3.6.11",
42
- "babel-plugin-transform-react-jsx-to-rn-stylesheet": "3.6.11"
38
+ "@tarojs/helper": "3.6.12",
39
+ "@tarojs/shared": "3.6.12"
43
40
  },
44
41
  "devDependencies": {
45
42
  "@babel/core": "^7.14.5",
package/rn/index.js CHANGED
@@ -1,114 +1,6 @@
1
- const PLATFORM_TYPE = require('@tarojs/shared').PLATFORM_TYPE
2
1
  const reactNativeBabelPreset = require('metro-react-native-babel-preset')
3
- const { merge } = require('lodash')
4
- const fs = require('fs')
5
- /**
6
- *
7
- * 获取项目级配置
8
- *
9
- */
10
- let config
11
- let rnConfig
12
- function getProjectConfig () {
13
- if (config) return config
14
- const fileName = `${process.cwd()}/config/index.js`
15
- if (fs.existsSync(fileName)) {
16
- config = require(`${process.cwd()}/config/index`)(merge)
17
- return config
18
- } else {
19
- console.warn('缺少项目基本配置')
20
- config = {}
21
- return config
22
- }
23
- }
24
-
25
- function getRNConfig () {
26
- const config = getProjectConfig()
27
- if (rnConfig) return rnConfig
28
- if (config.rn) {
29
- rnConfig = config.rn
30
- } else {
31
- rnConfig = {}
32
- }
33
- return rnConfig
34
- }
35
-
36
- /**
37
- * 配置环境变量
38
- */
39
- function getEnv () {
40
- const config = getProjectConfig()
41
- const envConst = {
42
- 'process.env.TARO_ENV': 'rn',
43
- 'process.env.TARO_PLATFORM': PLATFORM_TYPE.RN,
44
- }
45
- if (config.env) {
46
- Object.keys(config.env).forEach((key) => {
47
- try {
48
- envConst[`process.env.${key}`] = JSON.parse(config.env[key])
49
- } catch (e) {
50
- console.error('env环境配置有误' + config.env[key])
51
- }
52
- })
53
- }
54
- if (!config.env || !config.env.NODE_ENV) {
55
- if (process.env.NODE_ENV === 'development') {
56
- envConst['process.env.NODE_ENV'] = 'development'
57
- } else {
58
- envConst['process.env.NODE_ENV'] = 'production'
59
- }
60
- }
61
- return envConst
62
- }
63
-
64
- function parseDefineConst (config) {
65
- const result = {}
66
- Object.keys(config.defineConstants).forEach((key) => {
67
- try {
68
- result[key] = JSON.parse(config.defineConstants[key])
69
- } catch (e) {
70
- console.error('defineConstants error: ', e)
71
- result[key] = ''
72
- }
73
- })
74
- return result
75
- }
76
-
77
- /**
78
- * 配置常量
79
- * @returns {*}
80
- */
81
- function getDefineConstants () {
82
- const config = getProjectConfig()
83
- const rnconfig = getRNConfig()
84
- const env = getEnv()
85
- if (rnconfig.defineConstants) {
86
- return {
87
- ...parseDefineConst(rnconfig),
88
- ...env
89
- }
90
- }
91
- if (config.defineConstants) {
92
- return {
93
- ...parseDefineConst(config),
94
- ...env
95
- }
96
- }
97
- return env
98
- }
99
-
100
- function getCSSModule () {
101
- const rnconfig = getRNConfig()
102
- if (rnconfig.postcss && rnconfig.postcss.cssModules) {
103
- return rnconfig.postcss.cssModules.enable
104
- }
105
- return false
106
- }
107
2
 
108
3
  module.exports = (_, options = {}) => {
109
- if(!process.env.NODE_ENV) {
110
- process.env.NODE_ENV = 'development'
111
- }
112
4
  const {
113
5
  decoratorsBeforeExport,
114
6
  decoratorsLegacy
@@ -122,22 +14,10 @@ module.exports = (_, options = {}) => {
122
14
  const nativeLibs = require('@tarojs/taro-rn/libList.js')
123
15
  const nativeInterfaces = nativeApis.concat(nativeLibs)
124
16
 
125
- const defineConstants = getDefineConstants()
126
17
  const presets = []
127
18
  const plugins = []
128
- const { enableMultipleClassName = false, enableMergeStyle = false } = getRNConfig()
129
19
 
130
20
  presets.push(reactNativeBabelPreset(_, options))
131
- plugins.push(
132
- // React 17 jsx runtime 兼容
133
- [require('@babel/plugin-transform-react-jsx'), {
134
- runtime: options.reactJsxRuntime || 'automatic'
135
- }],
136
- [require('babel-plugin-transform-react-jsx-to-rn-stylesheet'), { enableCSSModule: getCSSModule(), enableMultipleClassName }]
137
- )
138
- if (enableMergeStyle) {
139
- plugins.push([require('babel-plugin-jsx-attributes-array-to-object'), { attributes: ['style'] }])
140
- }
141
21
  plugins.push(
142
22
  [require('babel-plugin-transform-imports-api').default, {
143
23
  packagesApis: new Map([
@@ -161,10 +41,8 @@ module.exports = (_, options = {}) => {
161
41
  }
162
42
  }
163
43
  }],
164
- [require('babel-plugin-global-define'), defineConstants]
165
44
  )
166
45
 
167
- // 添加一个默认 plugin, 与小程序/h5保持一致.
168
46
  plugins.push(
169
47
  [require('@babel/plugin-proposal-decorators'), {
170
48
  decoratorsBeforeExport,