Skip to content

Commit 6b0489e

Browse files
authored
chore: build an es5 bundle and move main to es6 (#1480)
1 parent a124ef5 commit 6b0489e

File tree

7 files changed

+113
-11
lines changed

7 files changed

+113
-11
lines changed

.babelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"presets": ["@babel/env", ["@babel/typescript", { "jsxPragma": "h" }]],
33
"plugins": [
4+
"@babel/plugin-transform-nullish-coalescing-operator",
45
[
56
"@babel/transform-react-jsx",
67
{

.github/workflows/ssr-es-check.yml renamed to .github/workflows/es-check.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Server-side rendering and ES5
1+
name: ES5 support check
22

33
on:
44
- pull_request
@@ -19,8 +19,5 @@ jobs:
1919

2020
- run: pnpm install && pnpm build
2121

22-
- name: Run es-check to check if our bundle is ES5 compatible
23-
run: npx [email protected] es5 dist/{array,main}.js
24-
25-
- name: Require module via node
26-
run: cd dist; node -e "require('./main')"
22+
- name: Run es-check to check if our ie11 bundle is ES5 compatible
23+
run: npx [email protected] es5 dist/array.full.es5.js

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,22 @@
3838
"react/package.json"
3939
],
4040
"dependencies": {
41+
"core-js": "^3.38.1",
4142
"fflate": "^0.4.8",
4243
"preact": "^10.19.3",
4344
"web-vitals": "^4.2.0"
4445
},
4546
"devDependencies": {
4647
"@babel/core": "7.18.9",
4748
"@babel/plugin-syntax-decorators": "^7.23.3",
49+
"@babel/plugin-transform-nullish-coalescing-operator": "^7.25.8",
4850
"@babel/plugin-transform-react-jsx": "^7.23.4",
4951
"@babel/preset-env": "7.18.9",
5052
"@babel/preset-typescript": "^7.18.6",
5153
"@cypress/skip-test": "^2.6.1",
5254
"@jest/globals": "^27.5.1",
5355
"@rollup/plugin-babel": "^6.0.4",
56+
"@rollup/plugin-commonjs": "^28.0.1",
5457
"@rollup/plugin-json": "^6.1.0",
5558
"@rollup/plugin-node-resolve": "^15.3.0",
5659
"@rollup/plugin-terser": "^0.4.4",

pnpm-lock.yaml

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rollup.config.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,37 @@ import typescript from '@rollup/plugin-typescript'
55
import { dts } from 'rollup-plugin-dts'
66
import terser from '@rollup/plugin-terser'
77
import { visualizer } from 'rollup-plugin-visualizer'
8+
import commonjs from '@rollup/plugin-commonjs'
89
import fs from 'fs'
910
import path from 'path'
1011

11-
const plugins = [
12+
const plugins = (es5) => [
1213
json(),
1314
resolve({ browser: true }),
1415
typescript({ sourceMap: true, outDir: './dist' }),
16+
commonjs(),
1517
babel({
1618
extensions: ['.js', '.jsx', '.ts', '.tsx'],
1719
babelHelpers: 'bundled',
20+
plugins: ['@babel/plugin-transform-nullish-coalescing-operator'],
1821
presets: [
1922
[
2023
'@babel/preset-env',
2124
{
22-
targets: '>0.5%, last 2 versions, Firefox ESR, not dead, IE 11',
25+
targets: es5
26+
? '>0.5%, last 2 versions, Firefox ESR, not dead, IE 11'
27+
: '>0.5%, last 2 versions, Firefox ESR, not dead',
2328
},
2429
],
2530
],
2631
}),
27-
terser({ toplevel: true }),
32+
terser({
33+
toplevel: true,
34+
compress: {
35+
// 5 is the default if unspecified
36+
ecma: es5 ? 5 : 6,
37+
},
38+
}),
2839
]
2940

3041
const entrypoints = fs.readdirSync('./src/entrypoints')
@@ -44,6 +55,8 @@ const entrypointTargets = entrypoints.map((file) => {
4455

4556
const fileName = fileParts.join('.')
4657

58+
const pluginsForThisFile = plugins(fileName.includes('es5'))
59+
4760
// we're allowed to console log in this file :)
4861
// eslint-disable-next-line no-console
4962
console.log(`Building ${fileName} in ${format} format`)
@@ -67,7 +80,7 @@ const entrypointTargets = entrypoints.map((file) => {
6780
...(format === 'cjs' ? { exports: 'auto' } : {}),
6881
},
6982
],
70-
plugins: [...plugins, visualizer({ filename: `bundle-stats-${fileName}.html` })],
83+
plugins: [...pluginsForThisFile, visualizer({ filename: `bundle-stats-${fileName}.html` })],
7184
}
7285
})
7386

src/entrypoints/array.full.es5.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// a straight copy of the array.full.ts entrypoint,
2+
// but will have different config when passed through rollup
3+
// to allow es5/IE11 support
4+
5+
// it doesn't include recorder which doesn't support IE11,
6+
// and it doesn't include web-vitals which doesn't support IE11
7+
8+
import './surveys'
9+
import './exception-autocapture'
10+
import './tracing-headers'
11+
import './array.no-external'

testcafe/helpers.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ export const staticFilesMock = RequestMock()
3333
.onRequestTo(/array.full.js/)
3434
.respond((req, res) => {
3535
// eslint-disable-next-line no-undef
36-
const arrayjs = fs.readFileSync(path.resolve(__dirname, '../dist/array.full.js'))
36+
const ENV_BROWSER = process.env.BROWSER
37+
const fileToRead = ENV_BROWSER === 'browserstack:ie' ? '../dist/array.full.es5.js' : '../dist/array.full.js'
38+
// eslint-disable-next-line no-undef
39+
const arrayjs = fs.readFileSync(path.resolve(__dirname, fileToRead))
3740
res.setBody(arrayjs)
3841
})
3942
.onRequestTo(/playground/)

0 commit comments

Comments
 (0)