forked from cagov/unemployment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.js
71 lines (67 loc) · 2.01 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
const transformDesignSystemImports = [
"babel-plugin-transform-imports",
{
"@cmsgov/design-system-core": {
transform:
// eslint-disable-next-line no-template-curly-in-string
"@cmsgov/design-system-core/dist/components/${member}/${member}",
preventFullImport: true,
},
},
];
module.exports = (api) => {
/**
* Cache based on the value of NODE_ENV. Any time the using callback returns
* a value other than the one that was expected, the overall config function
* will be called again and a new entry will be added to the cache.
*/
api.cache.using(() => process.env.NODE_ENV);
const config = {
env: {
test: {
// async/await fix for tests
plugins: ["@babel/plugin-transform-runtime"],
},
},
presets: [
[
"@babel/preset-env",
{
// This version should correspond with the major version of core-js
// NPM dependency installed
corejs: 3,
// Convert ES import/export syntax during tests, since Jest expects
// CommonJS, not ES import/export syntax
modules: api.env("test") ? "cjs" : false,
// tell babel to transpile to ES5 for older browsers
targets: {
browsers: ["> 1%"], // market share >1% includes IE11, for now
},
// replace the "core-js" and "regenerator-runtime/runtime" import
// statements with specific polyfills
useBuiltIns: "entry",
},
],
"@babel/preset-react",
],
plugins: [
// Allow parsing of import()
"syntax-dynamic-import",
// class { handleThing = () => { } }
"@babel/plugin-proposal-class-properties",
[
"@babel/plugin-proposal-object-rest-spread",
{
useBuiltIns: true,
},
],
transformDesignSystemImports,
],
};
if (api.env("production")) {
config.plugins.push.apply(config.plugins, [
"babel-plugin-transform-react-remove-prop-types",
]);
}
return config;
};