-
-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathbabel.config.js
75 lines (73 loc) · 2.41 KB
/
babel.config.js
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const { resolvePath } = require('babel-plugin-module-resolver');
const fs = require('fs');
const path = require('path');
module.exports = function (api) {
api.cache.using(() => process.env.NODE_ENV);
return {
presets: [
[
'@anansi',
{
hasJsxRuntime: true,
loose: true,
resolver: {
resolvePath(sourcePath, currentFile, opts) {
// babel needs to handle .js imports that refer to .ts files
if (
process.env.NODE_ENV === 'test' &&
sourcePath.startsWith('.') &&
(sourcePath.endsWith('.js') || sourcePath.endsWith('.cjs'))
) {
const removedExt = sourcePath.substring(
0,
sourcePath.lastIndexOf('.'),
);
return resolvePath(removedExt, currentFile, opts);
}
// for compiling CJS .native only outputs
if (
process.env.COMPILE_TARGET === 'native' &&
sourcePath.startsWith('.') &&
(sourcePath.endsWith('.js') || sourcePath.endsWith('.cjs')) &&
!sourcePath.includes('.native')
) {
const final =
sourcePath.substring(0, sourcePath.lastIndexOf('.')) +
'.native';
const resolved = resolvePath(final, currentFile, opts);
for (const ext of opts.extensions) {
const absolutePath = path.join(
path.dirname(currentFile),
resolved + ext,
);
if (fs.existsSync(absolutePath)) {
return resolved + path.extname(sourcePath);
}
}
}
},
root: [],
},
},
],
],
assumptions: {
noDocumentAll: true,
noClassCalls: true,
constantReexports: true,
objectRestNoSymbols: true,
pureGetters: true,
},
sourceMaps: 'inline',
// allows us to load .babelrc in addition to this
babelrcRoots: ['packages/*', '__tests__'],
// this is just for testing react native...they ship packages with flowtype in them
overrides: [
{
test: /node_modules\/.+\.(m|c)?js$/,
presets: ['@babel/preset-flow'],
plugins: ['babel-plugin-syntax-hermes-parser'],
},
],
};
};