UNPKG

1.4 kBJavaScriptView Raw
1// Inspiration: https://github.com/facebookincubator/create-react-app/blob/master/packages/babel-preset-react-app/index.js
2
3module.exports = (_api, opts) => {
4 // This is similar to how `env` works in Babel:
5 // https://babeljs.io/docs/usage/babelrc/#env-option
6 // We are not using `env` because it’s ignored in versions > babel-core@6.10.4:
7 // https://github.com/babel/babel/issues/4539
8 // https://github.com/facebook/create-react-app/issues/720
9 // It’s also nice that we can enforce `NODE_ENV` being specified.
10 const env = process.env.BABEL_ENV || process.env.NODE_ENV;
11
12 if (!opts) {
13 opts = {};
14 }
15 // const targets = validateBoolOption('targets',opts.targets);
16 const isEnvProduction = env === 'production';
17
18 return {
19 presets: [[require.resolve('babel-preset-react-app')]],
20 plugins: [
21 isEnvProduction && [
22 // Remove "data-test-id", "data-testid" attributes from production builds.
23 require.resolve('babel-plugin-jsx-remove-data-test-id'),
24 {
25 attributes: ['data-test-id', 'data-testid']
26 }
27 ],
28 [require.resolve('@babel/plugin-proposal-decorators'), { legacy: true }],
29 [
30 'babel-plugin-root-import',
31 {
32 rootPathSuffix: 'project/app',
33 rootPathPrefix: '@/'
34 }
35 ],
36 [require.resolve('@babel/plugin-proposal-optional-chaining')]
37 ].filter(Boolean)
38 };
39};