Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: build an es5 bundle and move main to es6 #1480

Merged
merged 13 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"presets": ["@babel/env", ["@babel/typescript", { "jsxPragma": "h" }]],
"plugins": [
"@babel/plugin-transform-nullish-coalescing-operator",
[
"@babel/transform-react-jsx",
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Server-side rendering and ES5
name: ES5 support check

on:
- pull_request
Expand All @@ -19,8 +19,5 @@ jobs:

- run: pnpm install && pnpm build

- name: Run es-check to check if our bundle is ES5 compatible
run: npx es-check@6.1.1 es5 dist/{array,main}.js

- name: Require module via node
run: cd dist; node -e "require('./main')"
- name: Run es-check to check if our ie11 bundle is ES5 compatible
run: npx es-check@7.2.1 es5 dist/array.full.es5.js
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,22 @@
"react/package.json"
],
"dependencies": {
"core-js": "^3.38.1",
"fflate": "^0.4.8",
"preact": "^10.19.3",
"web-vitals": "^4.2.0"
},
"devDependencies": {
"@babel/core": "7.18.9",
"@babel/plugin-syntax-decorators": "^7.23.3",
"@babel/plugin-transform-nullish-coalescing-operator": "^7.25.8",
"@babel/plugin-transform-react-jsx": "^7.23.4",
"@babel/preset-env": "7.18.9",
"@babel/preset-typescript": "^7.18.6",
"@cypress/skip-test": "^2.6.1",
"@jest/globals": "^27.5.1",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-terser": "^0.4.4",
Expand Down
74 changes: 74 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 17 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,37 @@ import typescript from '@rollup/plugin-typescript'
import { dts } from 'rollup-plugin-dts'
import terser from '@rollup/plugin-terser'
import { visualizer } from 'rollup-plugin-visualizer'
import commonjs from '@rollup/plugin-commonjs'
import fs from 'fs'
import path from 'path'

const plugins = [
const plugins = (es5) => [
json(),
resolve({ browser: true }),
typescript({ sourceMap: true, outDir: './dist' }),
commonjs(),
babel({
extensions: ['.js', '.jsx', '.ts', '.tsx'],
babelHelpers: 'bundled',
plugins: ['@babel/plugin-transform-nullish-coalescing-operator'],
presets: [
[
'@babel/preset-env',
{
targets: '>0.5%, last 2 versions, Firefox ESR, not dead, IE 11',
targets: es5
? '>0.5%, last 2 versions, Firefox ESR, not dead, IE 11'
: '>0.5%, last 2 versions, Firefox ESR, not dead',
},
],
],
}),
terser({ toplevel: true }),
terser({
toplevel: true,
compress: {
// 5 is the default if unspecified
ecma: es5 ? 5 : 6,
},
}),
]

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

const fileName = fileParts.join('.')

const pluginsForThisFile = plugins(fileName.includes('es5'))

// we're allowed to console log in this file :)
// eslint-disable-next-line no-console
console.log(`Building ${fileName} in ${format} format`)
Expand All @@ -67,7 +80,7 @@ const entrypointTargets = entrypoints.map((file) => {
...(format === 'cjs' ? { exports: 'auto' } : {}),
},
],
plugins: [...plugins, visualizer({ filename: `bundle-stats-${fileName}.html` })],
plugins: [...pluginsForThisFile, visualizer({ filename: `bundle-stats-${fileName}.html` })],
}
})

Expand Down
11 changes: 11 additions & 0 deletions src/entrypoints/array.full.es5.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// a straight copy of the array.full.ts entrypoint,
// but will have different config when passed through rollup
// to allow es5/IE11 support

// it doesn't include recorder which doesn't support IE11,
// and it doesn't include web-vitals which doesn't support IE11

import './surveys'
import './exception-autocapture'
import './tracing-headers'
import './array.no-external'
5 changes: 4 additions & 1 deletion testcafe/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export const staticFilesMock = RequestMock()
.onRequestTo(/array.full.js/)
.respond((req, res) => {
// eslint-disable-next-line no-undef
const arrayjs = fs.readFileSync(path.resolve(__dirname, '../dist/array.full.js'))
const ENV_BROWSER = process.env.BROWSER
const fileToRead = ENV_BROWSER === 'browserstack:ie' ? '../dist/array.full.es5.js' : '../dist/array.full.js'
// eslint-disable-next-line no-undef
const arrayjs = fs.readFileSync(path.resolve(__dirname, fileToRead))
res.setBody(arrayjs)
})
.onRequestTo(/playground/)
Expand Down
Loading