forked from redwoodjs/redwood
-
Notifications
You must be signed in to change notification settings - Fork 1
/
babel.config.js
117 lines (111 loc) · 3.87 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
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
106
107
108
109
110
111
112
113
114
115
116
117
const path = require('path')
const packageJSON = require(path.join(__dirname, 'package.json'))
// RedwoodJS targets Node.js 12.x because this is the default version
// for Netlify's functions.
const TARGETS_NODE = '12.16'
// Run `npx browserslist "defaults, not IE 11, not IE_Mob 11"` to see a list
// of target browsers.
const TARGETS_BROWSERS = ['defaults', 'not IE 11', 'not IE_Mob 11']
// Warning! Recommended to specify used minor core-js version, like corejs: '3.6',
// instead of corejs: '3', since with '3' it will not be injected modules
// which were added in minor core-js releases.
// https://github.com/zloirock/core-js/blob/master/README.md#babelpreset-env
const CORE_JS_VERSION = packageJSON.devDependencies['core-js']
.split('.')
.slice(0, 2)
.join('.') // Produces: 3.12, instead of 3.12.1
// 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-env',
{
targets: { node: TARGETS_NODE },
useBuiltIns: 'usage',
corejs: {
version: CORE_JS_VERSION,
// List of supported proposals: https://github.com/zloirock/core-js/blob/master/docs/2019-03-19-core-js-3-babel-and-a-look-into-the-future.md#ecmascript-proposals
proposals: true,
},
},
],
'@babel/preset-react',
'@babel/typescript',
],
plugins: [
/**
* NOTE
* Experimental decorators are used in `@redwoodjs/structure`.
* https://github.com/tc39/proposal-decorators
**/
['@babel/plugin-proposal-decorators', { legacy: true }],
// The "loose" option must be the same for all three of these plugins.
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-proposal-private-methods', { loose: true }],
['@babel/plugin-proposal-private-property-in-object', { loose: true }],
[
'@babel/plugin-transform-runtime',
{
// https://babeljs.io/docs/en/babel-plugin-transform-runtime/#core-js-aliasing
// Setting the version here also requires `@babel/runtime-corejs3`
corejs: { version: 3, proposals: true },
// https://babeljs.io/docs/en/babel-plugin-transform-runtime/#version
// Transform-runtime assumes that @babel/[email protected] is installed.
// Specifying the version can result in a smaller bundle size.
version: packageJSON.devDependencies['@babel/runtime-corejs3'],
},
],
],
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',
},
{
// import { PropTypes } from 'prop-types'
default: 'PropTypes',
path: 'prop-types',
},
],
},
],
// normally provided through preset-env detecting TARGET_BROWSER
// but webpack 4 has an issue with this
// see https://github.com/PaulLeCam/react-leaflet/issues/883
['@babel/plugin-proposal-nullish-coalescing-operator'],
],
},
],
// Ignore test directories when we're not testing
ignore:
process.env.NODE_ENV === 'test'
? []
: [/\.test\.(js|ts)/, '**/__tests__', '**/__mocks__', '**/__snapshots__'],
}