about summary refs log tree commit diff
path: root/babel.config.js
blob: a506ad8ce6e27031c5f021fd6e771991fc323b16 (plain) (blame)
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
module.exports = (api) => {
  const env = api.env();

  const envOptions = {
    debug: false,
    loose: true,
    modules: false,
  };

  const config = {
    presets: [
      '@babel/react',
      ['@babel/env', envOptions],
    ],
    plugins: [
      '@babel/syntax-dynamic-import',
      ['@babel/proposal-object-rest-spread', { useBuiltIns: true }],
      ['@babel/proposal-decorators', { legacy: true }],
      '@babel/proposal-class-properties',
      ['react-intl', { messagesDir: './build/messages' }],
      'preval',
    ],
  };

  switch (env) {
  case 'production':
    envOptions.debug = false;
    config.plugins.push(...[
      'lodash',
      [
        'transform-react-remove-prop-types',
        {
          mode: 'remove',
          removeImport: true,
          additionalLibraries: [
            'react-immutable-proptypes',
          ],
        },
      ],
      '@babel/transform-react-inline-elements',
      [
        '@babel/transform-runtime',
        {
          helpers: true,
          regenerator: false,
          useESModules: true,
        },
      ],
    ]);
    break;
  case 'development':
    envOptions.debug = true;
    config.plugins.push(...[
      '@babel/transform-react-jsx-source',
      '@babel/transform-react-jsx-self',
    ]);
    break;
  case 'test':
    envOptions.modules = 'commonjs';
    break;
  }

  return config;
};