-
Notifications
You must be signed in to change notification settings - Fork 18
/
.babelrc.js
190 lines (173 loc) · 5.82 KB
/
.babelrc.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/* eslint-disable prefer-template */
const path = require('path');
const aliases = require('./aliases');
// ///////////////////////////////////////////////////////////////
// ////////////////// PLUGINS ////////////////////////////////
// ///////////////////////////////////////////////////////////////
const commonPlugins = [
[
require.resolve('babel-plugin-module-resolver'),
{
root: [path.resolve('./')],
alias: aliases,
},
],
];
const relayTransformWatchPlugin = [
require.resolve('babel-plugin-transform-relay-hot'),
{
schema: './schema.graphql',
// compat: true,
watchInterval: 2000,
},
];
const relayTransformStaticPlugin = [
require.resolve('babel-plugin-transform-relay-hot'),
{
schema: './schema.graphql',
// compat: true,
watchInterval: 0, // disable watch
},
];
const commonNodePlugins = [
// Compiles import() to a deferred require()
// require.resolve('babel-plugin-dynamic-import-node'),
[
require.resolve('babel-plugin-import-inspector'),
{
serverSideRequirePath: true,
webpackRequireWeakId: true,
},
],
];
const commonBrowserPlugins = [
// Adds syntax support for import()
// Does not work with Webpack dynamic import. Eg. for SvgIcons
// require.resolve('babel-plugin-syntax-dynamic-import'),
[
require.resolve('babel-plugin-import-inspector'),
{
webpackRequireWeakId: true,
},
],
];
const reactDevelopmentPlugins = [
// The following two plugins are currently necessary to make React warnings
// include more valuable information. They are included here because they are
// currently not enabled in babel-preset-react. See the below threads for more info:
// https://github.com/babel/babel/issues/4702
// https://github.com/babel/babel/pull/3540#issuecomment-228673661
// https://github.com/facebookincubator/create-react-app/issues/989
// Adds component stack to warning messages
require.resolve('babel-plugin-transform-react-jsx-source'),
// Adds __self attribute to JSX which React will use for some warnings
require.resolve('babel-plugin-transform-react-jsx-self'),
];
const reactProductionPlugins = [
// improve production build,
// see https://medium.com/doctolib-engineering/improve-react-performance-with-babel-16f1becfaa25
// require.resolve('babel-plugin-transform-react-remove-prop-types'),
// require.resolve('babel-plugin-transform-react-inline-elements'),
// Optimization: hoist JSX that never changes out of render()
// Disabled because of issues:
// * https://github.com/facebookincubator/create-react-app/issues/525
// * https://phabricator.babeljs.io/search/query/pCNlnC2xzwzx/
// * https://github.com/babel/babel/issues/4516
// TODO: Enable again when these issues are resolved.
// require.resolve('babel-plugin-transform-react-constant-elements')
];
const inlineImportPlugin = [
require.resolve('babel-plugin-inline-import'),
{ extensions: ['.mjml', '.txt'] },
];
// ///////////////////////////////////////////////////////////////
// ////////////////// PRESETS ////////////////////////////////
// ///////////////////////////////////////////////////////////////
// ES features necessary for user's Node version
const nodeDevelopmentPreset = [
require.resolve('babel-preset-env'),
{
targets: {
node: 'current',
},
},
];
const nodeProductionPreset = [
require.resolve('babel-preset-env'),
{
targets: {
node: require('./package.json').engines.node,
},
},
];
// Latest stable ECMAScript features
const browserProductionPreset = [
require.resolve('babel-preset-env'),
{
targets: {
// React parses on ie 9, so we should too
ie: 9,
},
// We currently minify with uglify
// Remove after https://github.com/mishoo/UglifyJS2/issues/448
forceAllTransforms: true,
// Disable polyfill transforms
useBuiltIns: false,
// Do not transform modules to CJS
modules: false,
},
];
const browserDevelopmentPreset = [
require.resolve('babel-preset-env'),
{
targets: {
// chrome: 55,
browsers: ['last 2 versions', 'safari >= 10'],
},
// Disable polyfill transforms
useBuiltIns: false,
// Do not transform modules to CJS
modules: false,
},
];
// JSX, Flow
const reactPreset = require.resolve('babel-preset-react');
const flowPreset = require.resolve('babel-preset-flow');
// ///////////////////////////////////////////////////////////////
// ////////////////// EXPORT /////////////////////////////////
// ///////////////////////////////////////////////////////////////
module.exports = {
presets: [reactPreset, flowPreset, 'stage-0'],
plugins: [...commonPlugins],
env: {
browser_development: {
presets: [browserDevelopmentPreset, reactPreset, flowPreset, 'stage-0'],
plugins: [...reactDevelopmentPlugins, ...commonBrowserPlugins, relayTransformWatchPlugin],
},
browser_production: {
presets: [browserProductionPreset, reactPreset, flowPreset, 'stage-0'],
plugins: [relayTransformStaticPlugin, ...reactProductionPlugins, ...commonBrowserPlugins],
},
server_development: {
presets: [nodeDevelopmentPreset, reactPreset, flowPreset, 'stage-0'],
plugins: [...commonNodePlugins, ...reactDevelopmentPlugins, relayTransformWatchPlugin],
},
server_production: {
presets: [nodeProductionPreset, reactPreset, flowPreset, 'stage-0'],
plugins: [...commonNodePlugins, relayTransformStaticPlugin, ...reactProductionPlugins],
},
test: {
presets: [nodeDevelopmentPreset, reactPreset, flowPreset, 'stage-0'],
plugins: [
inlineImportPlugin,
...commonNodePlugins,
...reactDevelopmentPlugins,
relayTransformWatchPlugin,
],
},
scripts: {
presets: [nodeDevelopmentPreset, reactPreset, flowPreset, 'stage-0'],
plugins: [...commonPlugins, inlineImportPlugin],
},
},
};