-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathbabel.config.js
More file actions
105 lines (103 loc) · 3.34 KB
/
babel.config.js
File metadata and controls
105 lines (103 loc) · 3.34 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Run `npx browserslist "defaults"` to see a list of target browsers.
const TARGETS_BROWSERS = ['defaults']
// We use the recommended babel configuration for monorepos, which is a base directory
// `babel.config.js` file, but then use a per-project `.babelrc.js` file.
// Learn more: https://babeljs.io/docs/en/config-files#monorepos
/** @type {import('@babel/core').TransformOptions} */
module.exports = {
presets: [
['@babel/preset-react', { runtime: 'automatic' }],
/**
* TODO(pc): w/ '@babel/plugin-transform-typescript' in plugins now, is '@babel/typescript' preset still needed?
*
* - Plugins run before Presets.
* - Plugin ordering is first to last.
* - Preset ordering is reversed (last to first).
*
* https://babeljs.io/docs/en/plugins/#plugin-ordering
*/
'@babel/typescript',
],
plugins: [
/**
* NOTE
* Needed for react@18
*
* ```
* ✖ @cedarjs/router:build
* SyntaxError: /code/redwood/packages/router/src/location.tsx: TypeScript 'declare' fields must first be transformed by @babel/plugin-transform-typescript.
* If you have already enabled that plugin (or '@babel/preset-typescript'), make sure that it runs before any plugin related to additional class features:
* - @babel/plugin-proposal-class-properties
* - @babel/plugin-proposal-private-methods
* - @babel/plugin-proposal-decorators
* 25 | // When prerendering, there might be more than one level of location
* 26 | // providers. Use the values from the one above.
* > 27 | declare context: React.ContextType<typeof LocationContext>
* | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* 28 | HISTORY_LISTENER_ID: string | undefined = undefined
* 29 |
* 30 | state = {
* ```
*/
[
'@babel/plugin-transform-typescript',
{
allowDeclareFields: true,
/** needed in order build `packages/web/dist/entry/index.js` */
isTSX: true,
allExtensions: true,
},
],
/**
* NOTE
* Experimental decorators are used in `@cedarjs/structure`.
* https://github.com/tc39/proposal-decorators
**/
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-transform-runtime'],
'@babel/plugin-syntax-import-attributes',
],
overrides: [
// ** WEB PACKAGES **
{
test: [
'./packages/auth/',
'./packages/router',
'./packages/forms/',
'./packages/web/',
],
presets: [
[
'@babel/preset-env',
{
targets: {
browsers: TARGETS_BROWSERS,
},
},
],
],
plugins: [
[
'babel-plugin-auto-import',
{
declarations: [
{
// import { React } from 'react'
default: 'React',
path: 'react',
},
],
},
],
],
},
],
// Ignore test directories when we're not testing
// Note: No matter what you try to do here, babel will still include
// snapshot files in the dist output.
// See https://github.com/babel/babel/issues/11394
ignore:
process.env.NODE_ENV === 'test'
? []
: [/\.test\.(js|ts)/, '**/__tests__', '**/__mocks__', '**/__snapshots__'],
}