11module . exports = function ( api ) {
22 //api.cache(false)
33
4+ const isCJSBuild = process . env . RBC_CJS_BUILD === 'true'
5+ const isESMBuild = process . env . RBC_ESM_BUILD === 'true'
6+ const optionalPlugins = [ ]
7+
8+ if ( isESMBuild ) {
9+ optionalPlugins . push ( [
10+ 'babel-plugin-transform-rename-import' ,
11+ {
12+ replacements : [ { original : 'lodash' , replacement : 'lodash-es' } ] ,
13+ } ,
14+ ] )
15+ }
16+
417 const config = {
518 presets : [
619 [
@@ -13,27 +26,25 @@ module.exports = function (api) {
1326 } ) ,
1427 } ,
1528 ] ,
16- [ 'react-app' , { absoluteRuntime : false } ] ,
29+ // FIXME: Passing `useESModules` to babel-preset-react-app is an
30+ // undocumented feature. Should be avoided. This option is also deprecated
31+ // according to
32+ // https://babeljs.io/docs/en/babel-plugin-transform-runtime#useesmodules
33+ [
34+ 'react-app' ,
35+ {
36+ useESModules : ! isCJSBuild ,
37+ absoluteRuntime : false ,
38+ } ,
39+ ] ,
1740 ] ,
1841 plugins : [
1942 [ '@babel/plugin-transform-runtime' ] ,
2043 [ 'transform-react-remove-prop-types' , { mode : 'wrap' } ] ,
2144 [ '@babel/plugin-proposal-private-property-in-object' , { loose : true } ] ,
2245 [ '@babel/plugin-proposal-private-methods' , { loose : true } ] ,
46+ ...optionalPlugins ,
2347 ] ,
24- env : {
25- esm : {
26- presets : [ '@babel/preset-env' , 'react-app' ] ,
27- plugins : [
28- [
29- 'babel-plugin-transform-rename-import' ,
30- {
31- replacements : [ { original : 'lodash' , replacement : 'lodash-es' } ] ,
32- } ,
33- ] ,
34- ] ,
35- } ,
36- } ,
3748 }
3849
3950 return config
0 commit comments