Skip to content

Commit 687b121

Browse files
author
Sangeeth Sudheer
authored
fix: incorrect babel imports in CJS/ESM builds (#2157)
1 parent 475b109 commit 687b121

6 files changed

Lines changed: 52 additions & 31 deletions

File tree

.scripts/build.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ console.log(chalk.blue('Building js'))
1616
await $`NODE_ENV=production rollup -c`;
1717
console.log(chalk.blue(`Compiling 'lib' js files`))
1818
// build files used for overrides
19-
await $`NODE_ENV=production babel src --out-dir lib`
19+
await $`NODE_ENV=production RBC_CJS_BUILD=true babel src --out-dir lib`
2020
console.log(chalk.blue(`Copying SASS files to 'lib'`))
2121
// and since we don't currently use CSS modules...
2222
await fs.copy('./src/sass', './lib/sass')

.size-snapshot.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@
2424
}
2525
},
2626
"react-big-calendar.js": {
27-
"bundled": 1583365,
28-
"minified": 445101,
29-
"gzipped": 137464
27+
"bundled": 1583440,
28+
"minified": 445148,
29+
"gzipped": 137477
3030
},
3131
"react-big-calendar.min.js": {
32-
"bundled": 283536,
33-
"minified": 281826,
34-
"gzipped": 88860
32+
"bundled": 283203,
33+
"minified": 281754,
34+
"gzipped": 88847
3535
},
3636
"react-big-calendar.esm.js": {
37-
"bundled": 200119,
38-
"minified": 93592,
39-
"gzipped": 24251,
37+
"bundled": 199942,
38+
"minified": 93434,
39+
"gzipped": 24203,
4040
"treeshaked": {
4141
"rollup": {
42-
"code": 66279,
43-
"import_statements": 1777
42+
"code": 66290,
43+
"import_statements": 1804
4444
},
4545
"webpack": {
46-
"code": 70059
46+
"code": 70070
4747
}
4848
}
4949
}

babel.config.esm.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
process.env.RBC_ESM_BUILD = 'true'
2+
3+
module.exports = require('./babel.config')

babel.config.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
module.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

rollup.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import path from 'path'
12
import nodeResolve from '@rollup/plugin-node-resolve'
23
import babel from '@rollup/plugin-babel'
34
import commonjs from '@rollup/plugin-commonjs'
@@ -83,6 +84,12 @@ export default [
8384
},
8485
// prevent bundling all dependencies
8586
external: (id) => !id.startsWith('.') && !id.startsWith('/'),
86-
plugins: [babel(babelOptions), sizeSnapshot()],
87+
plugins: [
88+
babel({
89+
...babelOptions,
90+
configFile: path.join(__dirname, 'babel.config.esm.js'),
91+
}),
92+
sizeSnapshot(),
93+
],
8794
},
8895
]

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5296,9 +5296,9 @@ camelcase@^6.2.0:
52965296
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==
52975297

52985298
caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001297, caniuse-lite@^1.0.30001313:
5299-
version "1.0.30001314"
5300-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001314.tgz#65c7f9fb7e4594fca0a333bec1d8939662377596"
5301-
integrity sha512-0zaSO+TnCHtHJIbpLroX7nsD+vYuOVjl3uzFbJO1wMVbuveJA0RK2WcQA9ZUIOiO0/ArMiMgHJLxfEZhQiC0kw==
5299+
version "1.0.30001319"
5300+
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001319.tgz"
5301+
integrity sha512-xjlIAFHucBRSMUo1kb5D4LYgcN1M45qdKP++lhqowDpwJwGkpIRTt5qQqnhxjj1vHcI7nrJxWhCC1ATrCEBTcw==
53025302

53035303
capture-exit@^2.0.0:
53045304
version "2.0.0"

0 commit comments

Comments
 (0)