babel-preset-startupjs 0.59.0-canary.7 → 0.60.0-canary.0
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.
- package/index.js +41 -256
- package/package.json +6 -38
- package/constants.json +0 -3
- package/esNextPreset.js +0 -79
- package/metroPresetWithTypescript.js +0 -18
- package/pure.js +0 -86
package/index.js
CHANGED
|
@@ -1,264 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
[require('@startupjs/babel-plugin-transform-react-pug'), {
|
|
30
|
-
classAttribute: 'styleName'
|
|
31
|
-
}],
|
|
32
|
-
[require('@startupjs/babel-plugin-react-pug-classnames'), {
|
|
33
|
-
classAttribute: 'styleName'
|
|
34
|
-
}],
|
|
35
|
-
[require('@babel/plugin-proposal-decorators'), { legacy: true }]
|
|
36
|
-
]
|
|
37
|
-
|
|
38
|
-
const dotenvPlugin = ({ production, mockBaseUrl, envName = APP_ENV } = {}) => {
|
|
39
|
-
if (!envName) {
|
|
40
|
-
envName = production ? 'production' : 'local'
|
|
41
|
-
}
|
|
42
|
-
const options = {
|
|
43
|
-
moduleName: '@env',
|
|
44
|
-
path: ['.env', `.env.${envName}`]
|
|
45
|
-
}
|
|
46
|
-
if (mockBaseUrl) {
|
|
47
|
-
options.override = {
|
|
48
|
-
BASE_URL: "typeof window !== 'undefined' && window.location && window.location.origin"
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return [require('@startupjs/babel-plugin-dotenv'), options]
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const i18nPlugin = (options) => {
|
|
55
|
-
return [require('@startupjs/babel-plugin-i18n-extract'), options]
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const webReactCssModulesPlugin = ({ production } = {}) =>
|
|
59
|
-
['@startupjs/babel-plugin-react-css-modules', {
|
|
60
|
-
handleMissingStyleName: 'ignore',
|
|
61
|
-
webpackHotModuleReloading: !production,
|
|
62
|
-
filetypes: {
|
|
63
|
-
'.styl': {}
|
|
64
|
-
},
|
|
65
|
-
transform: (src, filepath) => {
|
|
66
|
-
if (!/\.styl$/.test(filepath)) return src
|
|
67
|
-
return stylusToCssLoader.call({ resourcePath: filepath }, src)
|
|
68
|
-
},
|
|
69
|
-
generateScopedName
|
|
70
|
-
}]
|
|
71
|
-
|
|
72
|
-
const nativeReactCssModulesPlatformExtensionsPlugin = () =>
|
|
73
|
-
[require('babel-plugin-react-native-platform-specific-extensions'), {
|
|
74
|
-
extensions: ['styl', 'css']
|
|
75
|
-
}]
|
|
76
|
-
|
|
77
|
-
const nativeReactCssModulesPlugins = ({ platform, useImport } = {}) => [
|
|
78
|
-
[require('@startupjs/babel-plugin-rn-stylename-to-style'), {
|
|
79
|
-
extensions: ['styl', 'css'],
|
|
80
|
-
useImport
|
|
81
|
-
}],
|
|
82
|
-
[require('@startupjs/babel-plugin-rn-stylename-inline'), {
|
|
83
|
-
platform
|
|
84
|
-
}]
|
|
85
|
-
]
|
|
86
|
-
|
|
87
|
-
// react-native config
|
|
88
|
-
|
|
89
|
-
const CONFIG_NATIVE_DEVELOPMENT = {
|
|
90
|
-
presets: [
|
|
91
|
-
[
|
|
92
|
-
require('./metroPresetWithTypescript'),
|
|
93
|
-
{ useTransformReactJSXExperimental: true }
|
|
94
|
-
]
|
|
95
|
-
],
|
|
96
|
-
plugins: [
|
|
97
|
-
[require('@startupjs/babel-plugin-startupjs-debug')],
|
|
98
|
-
dotenvPlugin(),
|
|
99
|
-
nativeReactCssModulesPlatformExtensionsPlugin(),
|
|
100
|
-
...nativeReactCssModulesPlugins({ useImport: false }),
|
|
101
|
-
i18nPlugin()
|
|
102
|
-
]
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const CONFIG_NATIVE_PRODUCTION = {
|
|
106
|
-
presets: [
|
|
107
|
-
[
|
|
108
|
-
require('./metroPresetWithTypescript'),
|
|
109
|
-
{ useTransformReactJSXExperimental: true }
|
|
110
|
-
]
|
|
111
|
-
],
|
|
112
|
-
plugins: [
|
|
113
|
-
dotenvPlugin({ production: true }),
|
|
114
|
-
nativeReactCssModulesPlatformExtensionsPlugin(),
|
|
115
|
-
...nativeReactCssModulesPlugins({ useImport: false }),
|
|
116
|
-
i18nPlugin()
|
|
117
|
-
]
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// web config for universal web/native project. Uses inline CSS styles, same as in react-native config,
|
|
121
|
-
// therefore only the react-native rules can be used.
|
|
122
|
-
|
|
123
|
-
const CONFIG_WEB_UNIVERSAL_DEVELOPMENT = {
|
|
124
|
-
presets: [
|
|
125
|
-
[require('./esNextPreset'), { debugJsx: true }]
|
|
126
|
-
// NOTE: If we start to face unknown errors in development or
|
|
127
|
-
// want to sync the whole presets/plugins stack with RN,
|
|
128
|
-
// just replace the optimized esNext preset above with the
|
|
129
|
-
// regular metro preset below:
|
|
130
|
-
// [require('./metroPresetWithTypescript')]
|
|
131
|
-
],
|
|
132
|
-
plugins: [
|
|
133
|
-
[require('@startupjs/babel-plugin-startupjs-debug')],
|
|
134
|
-
[require('react-refresh/babel'), { skipEnvCheck: true }],
|
|
135
|
-
dotenvPlugin({ mockBaseUrl: true }),
|
|
136
|
-
...nativeReactCssModulesPlugins({ platform: 'web' }),
|
|
137
|
-
i18nPlugin({ collectTranslations: true })
|
|
138
|
-
]
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const CONFIG_WEB_UNIVERSAL_PRODUCTION = {
|
|
142
|
-
presets: [
|
|
143
|
-
[require('./metroPresetWithTypescript'), {
|
|
144
|
-
disableImportExportTransform: !!ASYNC
|
|
145
|
-
}]
|
|
146
|
-
],
|
|
147
|
-
plugins: [
|
|
148
|
-
ASYNC && require('@startupjs/babel-plugin-startupjs'),
|
|
149
|
-
ASYNC && require('@startupjs/babel-plugin-import-to-react-lazy'),
|
|
150
|
-
dotenvPlugin({ production: true, mockBaseUrl: true }),
|
|
151
|
-
...nativeReactCssModulesPlugins({ platform: 'web' }),
|
|
152
|
-
i18nPlugin({ collectTranslations: true })
|
|
153
|
-
].filter(Boolean)
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (ASYNC) {
|
|
157
|
-
CONFIG_WEB_UNIVERSAL_PRODUCTION.sourceType = 'unambiguous'
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// web config for a pure web project. Uses babel-plugin-react-css-modules for CSS which allows
|
|
161
|
-
// to use the full browser CSS engine.
|
|
162
|
-
|
|
163
|
-
const CONFIG_WEB_PURE_DEVELOPMENT = {
|
|
164
|
-
presets: [
|
|
165
|
-
[require('./esNextPreset'), { debugJsx: true }]
|
|
166
|
-
// NOTE: If we start to face unknown errors in development or
|
|
167
|
-
// want to sync the whole presets/plugins stack with RN,
|
|
168
|
-
// just replace the optimized esNext preset above with the
|
|
169
|
-
// regular metro preset below:
|
|
170
|
-
// [require('./metroPresetWithTypescript')]
|
|
171
|
-
],
|
|
172
|
-
plugins: [
|
|
173
|
-
[require('@startupjs/babel-plugin-startupjs-debug')],
|
|
174
|
-
[require('react-refresh/babel'), { skipEnvCheck: true }],
|
|
175
|
-
dotenvPlugin({ mockBaseUrl: true }),
|
|
176
|
-
webReactCssModulesPlugin(),
|
|
177
|
-
i18nPlugin({ collectTranslations: true })
|
|
178
|
-
]
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const CONFIG_WEB_PURE_PRODUCTION = {
|
|
182
|
-
presets: [
|
|
183
|
-
[require('./metroPresetWithTypescript'), {
|
|
184
|
-
disableImportExportTransform: !!ASYNC
|
|
1
|
+
module.exports = (api, { platform, env } = {}) => {
|
|
2
|
+
return {
|
|
3
|
+
overrides: [{
|
|
4
|
+
test: isJsxSource,
|
|
5
|
+
plugins: [
|
|
6
|
+
// support JSX syntax
|
|
7
|
+
require('@babel/plugin-syntax-jsx')
|
|
8
|
+
]
|
|
9
|
+
}, {
|
|
10
|
+
test: isTypeScriptSource,
|
|
11
|
+
plugins: [
|
|
12
|
+
// support TypeScript syntax
|
|
13
|
+
require('@babel/plugin-syntax-typescript')
|
|
14
|
+
]
|
|
15
|
+
}, {
|
|
16
|
+
test: isTsxSource,
|
|
17
|
+
plugins: [
|
|
18
|
+
// support TypeScript + JSX syntax
|
|
19
|
+
[require('@babel/plugin-syntax-typescript'), {
|
|
20
|
+
isTSX: true
|
|
21
|
+
}]
|
|
22
|
+
]
|
|
23
|
+
}, {
|
|
24
|
+
plugins: [
|
|
25
|
+
// debugging features
|
|
26
|
+
env === 'development' && require('@startupjs/babel-plugin-startupjs-debug'),
|
|
27
|
+
require('@startupjs/babel-plugin-i18n-extract')
|
|
28
|
+
].filter(Boolean)
|
|
185
29
|
}]
|
|
186
|
-
|
|
187
|
-
plugins: [
|
|
188
|
-
dotenvPlugin({ production: true, mockBaseUrl: true }),
|
|
189
|
-
webReactCssModulesPlugin({ production: true }),
|
|
190
|
-
i18nPlugin({ collectTranslations: true })
|
|
191
|
-
]
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (ASYNC) {
|
|
195
|
-
CONFIG_WEB_PURE_PRODUCTION.sourceType = 'unambiguous'
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// node.js server config
|
|
199
|
-
|
|
200
|
-
const CONFIG_SERVER = {
|
|
201
|
-
presets: [
|
|
202
|
-
require('./esNextPreset')
|
|
203
|
-
// NOTE: If we start to face unknown errors or
|
|
204
|
-
// want to sync the whole presets/plugins stack with RN,
|
|
205
|
-
// just replace the optimized esNext preset above with the
|
|
206
|
-
// regular metro preset below:
|
|
207
|
-
// [require('./metroPresetWithTypescript')]
|
|
208
|
-
],
|
|
209
|
-
plugins: []
|
|
30
|
+
}
|
|
210
31
|
}
|
|
211
32
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
// There is a bug in metro when BABEL_ENV is a string "undefined".
|
|
218
|
-
// We have to workaround it and use NODE_ENV.
|
|
219
|
-
const env = (BABEL_ENV !== 'undefined' && BABEL_ENV) || NODE_ENV
|
|
220
|
-
|
|
221
|
-
const { presets = [], plugins = [], ...extra } = getConfig(env, MODE)
|
|
222
|
-
|
|
223
|
-
return {
|
|
224
|
-
presets,
|
|
225
|
-
plugins: basePlugins(options).concat(plugins),
|
|
226
|
-
...extra
|
|
227
|
-
}
|
|
33
|
+
// all files which are not .ts or .tsx are considered to be pure JS with JSX support
|
|
34
|
+
function isJsxSource (fileName) {
|
|
35
|
+
if (!fileName) return false
|
|
36
|
+
return !isTypeScriptSource(fileName) && !isTsxSource(fileName)
|
|
228
37
|
}
|
|
229
38
|
|
|
230
|
-
function
|
|
231
|
-
if (
|
|
232
|
-
|
|
233
|
-
} else if (env === 'production') {
|
|
234
|
-
return CONFIG_NATIVE_PRODUCTION
|
|
235
|
-
} else if (env === 'server') {
|
|
236
|
-
return CONFIG_SERVER
|
|
237
|
-
} else if (env === 'web_development') {
|
|
238
|
-
if (mode === 'web') {
|
|
239
|
-
return CONFIG_WEB_PURE_DEVELOPMENT
|
|
240
|
-
} else {
|
|
241
|
-
return CONFIG_WEB_UNIVERSAL_DEVELOPMENT
|
|
242
|
-
}
|
|
243
|
-
} else if (env === 'web_production') {
|
|
244
|
-
if (mode === 'web') {
|
|
245
|
-
return CONFIG_WEB_PURE_PRODUCTION
|
|
246
|
-
} else {
|
|
247
|
-
return CONFIG_WEB_UNIVERSAL_PRODUCTION
|
|
248
|
-
}
|
|
249
|
-
} else {
|
|
250
|
-
return {}
|
|
251
|
-
}
|
|
39
|
+
function isTypeScriptSource (fileName) {
|
|
40
|
+
if (!fileName) return false
|
|
41
|
+
return fileName.endsWith('.ts')
|
|
252
42
|
}
|
|
253
43
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
)
|
|
260
|
-
}
|
|
261
|
-
hashSize = Number(hashSize[1])
|
|
262
|
-
if (new RegExp(`_.{${hashSize}}_$`).test(name)) return name
|
|
263
|
-
return generateScopedNameFactory(LOCAL_IDENT_NAME)(name, filename)
|
|
44
|
+
// NOTE: .tsx is the default when fileName is not provided.
|
|
45
|
+
// This is because we want to support the most overarching syntax by default.
|
|
46
|
+
function isTsxSource (fileName) {
|
|
47
|
+
if (!fileName) return true
|
|
48
|
+
return fileName.endsWith('.tsx')
|
|
264
49
|
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-preset-startupjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.60.0-canary.0",
|
|
4
4
|
"description": "Babel preset for compiling StartupJS app on server, web, native",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"exports": {
|
|
7
|
-
".": "./index.js"
|
|
8
|
-
"./index.js": "./index.js",
|
|
9
|
-
"./pure": "./pure.js",
|
|
10
|
-
"./pure.js": "./pure.js",
|
|
11
|
-
"./constants": "./constants.json",
|
|
12
|
-
"./constants.json": "./constants.json"
|
|
7
|
+
".": "./index.js"
|
|
13
8
|
},
|
|
14
9
|
"publishConfig": {
|
|
15
10
|
"access": "public"
|
|
@@ -17,38 +12,11 @@
|
|
|
17
12
|
"license": "MIT",
|
|
18
13
|
"dependencies": {
|
|
19
14
|
"@babel/core": "^7.9.0",
|
|
20
|
-
"@babel/plugin-proposal-class-properties": "^7.0.0",
|
|
21
|
-
"@babel/plugin-proposal-decorators": "^7.8.0",
|
|
22
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.1",
|
|
23
|
-
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
|
|
24
|
-
"@babel/plugin-syntax-flow": "^7.2.0",
|
|
25
15
|
"@babel/plugin-syntax-jsx": "^7.0.0",
|
|
26
16
|
"@babel/plugin-syntax-typescript": "^7.23.3",
|
|
27
|
-
"@babel
|
|
28
|
-
"@babel
|
|
29
|
-
"@babel
|
|
30
|
-
"@babel/plugin-transform-react-jsx-self": "^7.0.0",
|
|
31
|
-
"@babel/plugin-transform-react-jsx-source": "^7.0.0",
|
|
32
|
-
"@babel/plugin-transform-runtime": "^7.0.0",
|
|
33
|
-
"@babel/plugin-transform-typescript": "^7.5.0",
|
|
34
|
-
"@babel/runtime": "^7.9.0",
|
|
35
|
-
"@startupjs/babel-plugin-dotenv": "^0.59.0-canary.0",
|
|
36
|
-
"@startupjs/babel-plugin-i18n-extract": "^0.59.0-canary.0",
|
|
37
|
-
"@startupjs/babel-plugin-import-to-react-lazy": "^0.59.0-canary.0",
|
|
38
|
-
"@startupjs/babel-plugin-react-css-modules": "^6.5.4-1",
|
|
39
|
-
"@startupjs/babel-plugin-react-pug-classnames": "^0.59.0-canary.0",
|
|
40
|
-
"@startupjs/babel-plugin-rn-stylename-inline": "^0.59.0-canary.7",
|
|
41
|
-
"@startupjs/babel-plugin-rn-stylename-to-style": "^0.59.0-canary.0",
|
|
42
|
-
"@startupjs/babel-plugin-startupjs": "^0.59.0-canary.0",
|
|
43
|
-
"@startupjs/babel-plugin-startupjs-debug": "^0.59.0-canary.0",
|
|
44
|
-
"@startupjs/babel-plugin-startupjs-utils": "^0.59.0-canary.0",
|
|
45
|
-
"@startupjs/babel-plugin-transform-react-pug": "^7.0.1-0",
|
|
46
|
-
"@startupjs/bundler": "^0.59.0-canary.7",
|
|
47
|
-
"babel-plugin-module-resolver": "^5.0.0",
|
|
48
|
-
"babel-plugin-react-native-platform-specific-extensions": "^1.1.1",
|
|
49
|
-
"babel-plugin-react-native-web-pass-classname": "^0.2.1",
|
|
50
|
-
"metro-react-native-babel-preset": "^0.76.8",
|
|
51
|
-
"react-refresh": "^0.10.0"
|
|
17
|
+
"@startupjs/babel-plugin-i18n-extract": "^0.60.0-canary.0",
|
|
18
|
+
"@startupjs/babel-plugin-startupjs": "^0.60.0-canary.0",
|
|
19
|
+
"@startupjs/babel-plugin-startupjs-debug": "^0.60.0-canary.0"
|
|
52
20
|
},
|
|
53
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "4c5baa750402d0beb02921a38413620b348bd374"
|
|
54
22
|
}
|
package/constants.json
DELETED
package/esNextPreset.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// This is the same preset as metro's, but everything which is supported
|
|
2
|
-
// by Node 14+ and latest Chrome is stripped out.
|
|
3
|
-
|
|
4
|
-
module.exports = ({ debugJsx }) => {
|
|
5
|
-
const defaultPlugins = [
|
|
6
|
-
[require('@babel/plugin-syntax-flow')],
|
|
7
|
-
[require('@babel/plugin-proposal-nullish-coalescing-operator')],
|
|
8
|
-
[require('@babel/plugin-proposal-optional-chaining'), { loose: true }],
|
|
9
|
-
[require('@babel/plugin-proposal-class-properties'), { loose: true }],
|
|
10
|
-
[require('@babel/plugin-transform-function-name')]
|
|
11
|
-
]
|
|
12
|
-
const extraPlugins = [
|
|
13
|
-
[require('@babel/plugin-transform-react-jsx')],
|
|
14
|
-
...(debugJsx
|
|
15
|
-
? [
|
|
16
|
-
require('@babel/plugin-transform-react-jsx-source'),
|
|
17
|
-
require('@babel/plugin-transform-react-jsx-self')
|
|
18
|
-
]
|
|
19
|
-
: []),
|
|
20
|
-
[
|
|
21
|
-
require('@babel/plugin-transform-runtime'),
|
|
22
|
-
{
|
|
23
|
-
helpers: true,
|
|
24
|
-
regenerator: true
|
|
25
|
-
}
|
|
26
|
-
]
|
|
27
|
-
]
|
|
28
|
-
return {
|
|
29
|
-
comments: false,
|
|
30
|
-
compact: true,
|
|
31
|
-
overrides: [
|
|
32
|
-
// the flow strip types plugin must go BEFORE class properties!
|
|
33
|
-
// there'll be a test case that fails if you don't.
|
|
34
|
-
{
|
|
35
|
-
plugins: [require('@babel/plugin-transform-flow-strip-types')]
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
plugins: defaultPlugins
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
test: isTypeScriptSource,
|
|
42
|
-
plugins: [
|
|
43
|
-
[
|
|
44
|
-
require('@babel/plugin-transform-typescript'),
|
|
45
|
-
{
|
|
46
|
-
isTSX: false,
|
|
47
|
-
allowNamespaces: true,
|
|
48
|
-
onlyRemoveTypeImports: true
|
|
49
|
-
}
|
|
50
|
-
]
|
|
51
|
-
]
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
test: isTSXSource,
|
|
55
|
-
plugins: [
|
|
56
|
-
[
|
|
57
|
-
require('@babel/plugin-transform-typescript'),
|
|
58
|
-
{
|
|
59
|
-
isTSX: true,
|
|
60
|
-
allowNamespaces: true,
|
|
61
|
-
onlyRemoveTypeImports: true
|
|
62
|
-
}
|
|
63
|
-
]
|
|
64
|
-
]
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
plugins: extraPlugins
|
|
68
|
-
}
|
|
69
|
-
]
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function isTypeScriptSource (fileName) {
|
|
74
|
-
return !!fileName && fileName.endsWith('.ts')
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function isTSXSource (fileName) {
|
|
78
|
-
return !!fileName && fileName.endsWith('.tsx')
|
|
79
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// metro has a hardcoded config for typescript babel plugin options.
|
|
2
|
-
// Here we run the default metro preset and then find the typescript plugin and monkeypatch
|
|
3
|
-
// its options to add the required 'onlyRemoveTypeImports: true' option.
|
|
4
|
-
// Without this option pug-related and style imports are gonna get stripped by typescript.
|
|
5
|
-
const metroPreset = require('metro-react-native-babel-preset')
|
|
6
|
-
|
|
7
|
-
module.exports = (...args) => patchTypescriptOptions(metroPreset(...args))
|
|
8
|
-
|
|
9
|
-
function patchTypescriptOptions (config) {
|
|
10
|
-
for (const override of config.overrides || []) {
|
|
11
|
-
for (const plugin of override.plugins || []) {
|
|
12
|
-
if (Array.isArray(plugin) && plugin[1] && plugin[1].isTSX != null) {
|
|
13
|
-
plugin[1].onlyRemoveTypeImports = true
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return config
|
|
18
|
-
}
|
package/pure.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
module.exports = (api, { platform, env } = {}) => {
|
|
2
|
-
return {
|
|
3
|
-
overrides: [{
|
|
4
|
-
test: isJsxSource,
|
|
5
|
-
plugins: [
|
|
6
|
-
// support JSX syntax
|
|
7
|
-
require('@babel/plugin-syntax-jsx')
|
|
8
|
-
]
|
|
9
|
-
}, {
|
|
10
|
-
test: isTypeScriptSource,
|
|
11
|
-
plugins: [
|
|
12
|
-
// support TypeScript syntax
|
|
13
|
-
require('@babel/plugin-syntax-typescript')
|
|
14
|
-
]
|
|
15
|
-
}, {
|
|
16
|
-
test: isTsxSource,
|
|
17
|
-
plugins: [
|
|
18
|
-
// support TypeScript + JSX syntax
|
|
19
|
-
[require('@babel/plugin-syntax-typescript'), {
|
|
20
|
-
isTSX: true
|
|
21
|
-
}]
|
|
22
|
-
]
|
|
23
|
-
}, {
|
|
24
|
-
plugins: [
|
|
25
|
-
// transform pug to jsx. This generates a bunch of new AST nodes
|
|
26
|
-
// (it's important to do this first before any dead code elimination runs)
|
|
27
|
-
[require('@startupjs/babel-plugin-transform-react-pug'), {
|
|
28
|
-
classAttribute: 'styleName'
|
|
29
|
-
}],
|
|
30
|
-
// support calling sub-components in pug (like <Modal.Header />)
|
|
31
|
-
[require('@startupjs/babel-plugin-react-pug-classnames'), {
|
|
32
|
-
classAttribute: 'styleName'
|
|
33
|
-
}],
|
|
34
|
-
// turning on experimental startupjs features
|
|
35
|
-
[require('@startupjs/babel-plugin-startupjs-utils'), {
|
|
36
|
-
observerCache: true,
|
|
37
|
-
signals: true
|
|
38
|
-
}],
|
|
39
|
-
// debugging features
|
|
40
|
-
env === 'development' && require('@startupjs/babel-plugin-startupjs-debug'),
|
|
41
|
-
// .env files support for client
|
|
42
|
-
[require('@startupjs/babel-plugin-dotenv'), (() => {
|
|
43
|
-
const envName = env === 'production' ? 'production' : 'local'
|
|
44
|
-
const options = {
|
|
45
|
-
moduleName: '@env',
|
|
46
|
-
path: ['.env', `.env.${envName}`]
|
|
47
|
-
}
|
|
48
|
-
if (platform === 'web') {
|
|
49
|
-
options.override = {
|
|
50
|
-
BASE_URL: "typeof window !== 'undefined' && window.location && window.location.origin"
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return options
|
|
54
|
-
})()],
|
|
55
|
-
// CSS modules (separate .styl/.css file)
|
|
56
|
-
[require('@startupjs/babel-plugin-rn-stylename-to-style'), {
|
|
57
|
-
extensions: ['styl', 'css'],
|
|
58
|
-
useImport: true
|
|
59
|
-
}],
|
|
60
|
-
// inline CSS modules (styl`` in the same JSX file -- similar to how it is in Vue.js)
|
|
61
|
-
[require('@startupjs/babel-plugin-rn-stylename-inline'), {
|
|
62
|
-
platform
|
|
63
|
-
}],
|
|
64
|
-
require('@startupjs/babel-plugin-i18n-extract')
|
|
65
|
-
].filter(Boolean)
|
|
66
|
-
}]
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// all files which are not .ts or .tsx are considered to be pure JS with JSX support
|
|
71
|
-
function isJsxSource (fileName) {
|
|
72
|
-
if (!fileName) return false
|
|
73
|
-
return !isTypeScriptSource(fileName) && !isTsxSource(fileName)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function isTypeScriptSource (fileName) {
|
|
77
|
-
if (!fileName) return false
|
|
78
|
-
return fileName.endsWith('.ts')
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// NOTE: .tsx is the default when fileName is not provided.
|
|
82
|
-
// This is because we want to support the most overarching syntax by default.
|
|
83
|
-
function isTsxSource (fileName) {
|
|
84
|
-
if (!fileName) return true
|
|
85
|
-
return fileName.endsWith('.tsx')
|
|
86
|
-
}
|