1 | // This file is formatted as JSON5 https://github.com/json5/json5
|
2 | {
|
3 | presets: [
|
4 | // Transforms JSX
|
5 | '@babel/preset-react',
|
6 | // Transforms ES6 code and import/export statements
|
7 | [
|
8 | '@babel/preset-env',
|
9 | {
|
10 | targets: {
|
11 | electron: '2.0.0',
|
12 | node: '8',
|
13 | browsers: ['last 2 versions', 'not ie < 11']
|
14 | },
|
15 | // Only use polyfills necessary for target env
|
16 | useBuiltIns: 'usage',
|
17 | corejs: 3,
|
18 | shippedProposals: true
|
19 | }
|
20 | ]
|
21 | ],
|
22 | plugins: [
|
23 | // Reduces bundle size by sharing babel helpers between files
|
24 | ['@babel/plugin-transform-runtime', { corejs: 3 }],
|
25 | // Allows simpler defineMessages with react-intl
|
26 | // https://github.com/akameco/babel-plugin-react-intl-auto
|
27 | ['react-intl-auto', { filebase: true, removePrefix: 'src' }],
|
28 | // Turns flow type annotations into React.PropTypes for runtime
|
29 | // type checking. Deadcode wraps in NODE_ENV checks
|
30 | // ['flow-react-proptypes', { deadCode: true }],
|
31 | // Converts flow annotations into comment syntax
|
32 | // https://flow.org/en/docs/types/comments/
|
33 | '@babel/plugin-transform-flow-comments',
|
34 | // Allows directly declaring props and methods on a class instead of
|
35 | // binding them to `this` in the constructor
|
36 | '@babel/plugin-proposal-class-properties',
|
37 | // Allows short hand of Object.assign({}, a) as {...a}
|
38 | // useBuiltIns should be fine for our use-case, but could cause un-expected
|
39 | // results if trying to spread objects with a prototype chains. See
|
40 | // https://exploringjs.com/es6/ch_oop-besides-classes.html#sec_assigning-vs-defining-properties
|
41 | [
|
42 | '@babel/plugin-proposal-object-rest-spread',
|
43 | { loose: true, useBuiltIns: true }
|
44 | ]
|
45 | ],
|
46 | env: {
|
47 | esm: {
|
48 | plugins: [
|
49 | [
|
50 | 'react-intl-auto',
|
51 | { filebase: true, extractComments: false, removePrefix: 'src' }
|
52 | ],
|
53 | // Creates shorter message hashes to reduce bundle size
|
54 | 'react-intl-id-hash'
|
55 | ],
|
56 | presets: [
|
57 | [
|
58 | '@babel/preset-env',
|
59 | {
|
60 | targets: {
|
61 | // Our main target for these modules is the mapeo-desktop electron
|
62 | // application.
|
63 | electron: '2.0.0'
|
64 | },
|
65 | modules: false,
|
66 | // Only use polyfills necessary for target env
|
67 | useBuiltIns: 'usage',
|
68 | corejs: 3,
|
69 | shippedProposals: true
|
70 | }
|
71 | ]
|
72 | ]
|
73 | },
|
74 | cjs: {
|
75 | plugins: [
|
76 | [
|
77 | 'react-intl-auto',
|
78 | { filebase: true, extractComments: false, removePrefix: 'src' }
|
79 | ],
|
80 | // Creates shorter message hashes to reduce bundle size
|
81 | 'react-intl-id-hash'
|
82 | ]
|
83 | }
|
84 | }
|
85 | }
|