Skip to content

Commit ef5d0a3

Browse files
authored
Fix: Compilation configs polyfill fixes (#404)
After some research it seems that most libraries do not include polyfills from Babel+core-js in their outputs. PR removes the corejs configs from Babel to fix broken build.
1 parent d0e9622 commit ef5d0a3

File tree

3 files changed

+53
-87
lines changed

3 files changed

+53
-87
lines changed

.babelrc.js

+41-77
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,49 @@
11
'use strict'
22

3-
/* eslint-disable import/extensions */
3+
/**
4+
* @file Compilation configuration
5+
*
6+
* Library is compiled to two targets before publishing, a CommonJS version and
7+
* an ESModules version. Both are compiled to work across the maximum number of
8+
* active browsers using Browserslist "defaults" target
9+
* (https://github.com/browserslist/browserslist#best-practices).
10+
*
11+
* Polyfills are _not_ included in the compilation: There is no clear guidance
12+
* on whether they should be included and most libraries do not include them.
13+
* This is probably because most current frameworks, like Next.js and Create
14+
* React App, include their own set of sensible polyfills.
15+
*/
416

5-
module.exports = {
6-
// Base configs are used by ESLint babel parser
7-
presets: ['@babel/preset-react', '@babel/preset-typescript'],
17+
const { BABEL_ENV } = process.env
818

9-
env: {
10-
/**
11-
* Test env mimics production, but uses commonjs modules because Jest
12-
* doesn't support ESModules and operates directly on source code.
13-
*/
14-
test: {
15-
presets: [
16-
['@babel/preset-env', { modules: 'commonjs', targets: 'node 16' }],
17-
'@babel/preset-react',
18-
'@babel/preset-typescript',
19-
],
20-
plugins: [],
21-
},
19+
const targets = BABEL_ENV === 'test' ? 'node 16' : 'defaults' // Testing runs in Node
20+
const useESM = BABEL_ENV === 'browser'
2221

23-
// Publish targets
24-
// ---------------------------------------------------------------------------
25-
26-
// CommonJS - ES5 syntax with commonJS modules
27-
commonjs: {
28-
presets: [
29-
[
30-
'@babel/preset-env',
31-
{
32-
corejs: '3',
33-
modules: 'commonjs',
34-
targets: 'node 14',
35-
useBuiltIns: 'usage',
36-
},
22+
module.exports = {
23+
// Base configs are used by ESLint babel parser
24+
presets: [
25+
[
26+
'@babel/preset-env',
27+
{
28+
bugfixes: true,
29+
modules: useESM ? false : 'commonjs',
30+
targets,
31+
exclude: [
32+
'transform-typeof-symbol', // https://github.com/facebook/create-react-app/issues/5277
3733
],
38-
'@babel/preset-react',
39-
'@babel/preset-typescript',
40-
],
41-
plugins: [
42-
[
43-
'@babel/plugin-transform-runtime',
34+
},
35+
],
36+
['@babel/preset-react', { runtime: 'automatic' }],
37+
'@babel/preset-typescript',
38+
],
4439

45-
{
46-
corejs: '3',
47-
helpers: true,
48-
regenerator: true,
49-
useESModules: false,
50-
version: '^7.17.0', // Include version for smaller bundle
51-
},
52-
],
53-
],
54-
},
55-
// ESM - ES5 syntax with ESModules
56-
browser: {
57-
presets: [
58-
[
59-
'@babel/preset-env',
60-
{
61-
corejs: '3',
62-
modules: false,
63-
targets: 'defaults',
64-
useBuiltIns: 'usage',
65-
},
66-
],
67-
'@babel/preset-react',
68-
'@babel/preset-typescript',
69-
],
70-
plugins: [
71-
[
72-
'@babel/plugin-transform-runtime',
73-
{
74-
corejs: '3',
75-
helpers: true,
76-
regenerator: true,
77-
useESModules: true,
78-
version: '^7.17.0', // Include version for smaller bundle
79-
},
80-
],
81-
],
82-
},
83-
// ℹ️ Local dev uses the default Storybook Babel configs
84-
},
40+
plugins: [
41+
[
42+
'@babel/plugin-transform-runtime',
43+
{
44+
useESModules: useESM,
45+
version: '^7.17.0', // Default is 7.0, include current version for smaller bundle improvements
46+
},
47+
],
48+
],
8549
}

package-lock.json

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
"version": "4.0.0-beta.3",
44
"description": "React component library for building custom design systems",
55
"sideEffects": false,
6-
"types": "types/index.d.ts",
76
"exports": {
87
"browser": "./dist/browser/index.js",
98
"node": {
109
"module": "./dist/browser/index.js",
11-
"require": "./dist/commonjs/index.cjs"
10+
"require": "./dist/commonjs/index.js"
1211
},
1312
"default": "./dist/browser/index.js"
1413
},
14+
"main": "./dist/commonjs/index.js",
15+
"module": "./dist/browser/index.js",
16+
"types": "./types/index.d.ts",
1517
"keywords": [
1618
"accessibility",
1719
"components-library",

0 commit comments

Comments
 (0)