Skip to content

Commit 9854a95

Browse files
authored
[sc193803] Rollup react sdk output (#107)
This PR introduces rollup to bundle the react sdk output: 1. The rollup config is in typescript. It shares the default tsconfig.json with the project hence these warnings of `rollup.config.ts` which can be safely ignored. 2. We now support both cjs and esm. 3. As above. 4. Type definitions are also generated by rollup. ![Screenshot_2023-07-10_at_3_28_42_PM](https://github.com/launchdarkly/react-client-sdk-private/assets/1593077/14180ee9-18ee-4c1e-839f-bb2047b58215) --------- Co-authored-by: Yusinto Ngadiman <[email protected]>
1 parent 97fa28a commit 9854a95

File tree

5 files changed

+75
-5
lines changed

5 files changed

+75
-5
lines changed

examples/typescript/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,3 @@
2121
npm-debug.log*
2222
yarn-debug.log*
2323
yarn-error.log*
24-
25-
public

examples/typescript/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
"start": "react-scripts start",
2323
"build": "react-scripts build",
2424
"test": "react-scripts test",
25-
"eject": "react-scripts eject"
25+
"eject": "react-scripts eject",
26+
"postinstall": "cd ../../ && yarn link-dev",
27+
"tsc": "tsc"
2628
},
2729
"eslintConfig": {
2830
"extends": [
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang='en'>
3+
<head>
4+
<meta charset='UTF-8'>
5+
<title>Title</title>
6+
</head>
7+
<body>
8+
<div id="root"></div>
9+
</body>
10+
</html>

package.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
"sdk",
1313
"bindings"
1414
],
15-
"main": "lib/index.js",
15+
"exports": {
16+
"require": "./lib/cjs/index.js",
17+
"import": "./lib/esm/index.js"
18+
},
19+
"main": "./lib/cjs/index.js",
1620
"types": "lib/index.d.ts",
1721
"files": [
1822
"lib",
@@ -23,7 +27,10 @@
2327
"scripts": {
2428
"test": "jest",
2529
"test:junit": "jest --ci --reporters=default --reporters=jest-junit",
26-
"build": "rimraf lib/* && tsc && mv lib/src/* lib && rimraf lib/package.json lib/src lib/*.test.*",
30+
"clean": "rimraf lib/*",
31+
"rb": "rollup -c --configPlugin typescript",
32+
"rbw": "yarn rb --watch",
33+
"build": "yarn clean && yarn rb",
2734
"lint": "tslint -p tsconfig.json 'src/**/*.ts*'",
2835
"lint:all": "npm run lint",
2936
"check-typescript": "tsc",
@@ -38,6 +45,10 @@
3845
},
3946
"homepage": "https://github.com/launchdarkly/react-client-sdk",
4047
"devDependencies": {
48+
"@rollup/plugin-json": "^6.0.0",
49+
"@rollup/plugin-node-resolve": "^15.1.0",
50+
"@rollup/plugin-terser": "^0.4.3",
51+
"@rollup/plugin-typescript": "^11.1.2",
4152
"@testing-library/jest-dom": "^5.16.4",
4253
"@testing-library/react": "^13.0.1",
4354
"@types/hoist-non-react-statics": "^3.3.1",
@@ -47,6 +58,7 @@
4758
"@types/react": "^18.0.3",
4859
"@types/react-dom": "^18.0.0",
4960
"@types/react-test-renderer": "^18.0.0",
61+
"esbuild": "^0.18.11",
5062
"jest": "^27.4.4",
5163
"jest-environment-jsdom": "^27.4.4",
5264
"jest-environment-jsdom-global": "^3.0.0",
@@ -57,6 +69,10 @@
5769
"react-dom": "^18.0.0",
5870
"react-test-renderer": "^18.0.0",
5971
"rimraf": "^3.0.0",
72+
"rollup": "^3.26.2",
73+
"rollup-plugin-dts": "^5.3.0",
74+
"rollup-plugin-esbuild": "^5.0.0",
75+
"rollup-plugin-filesize": "^10.0.0",
6076
"ts-jest": "^27.1.1",
6177
"tslint": "^6.1.3",
6278
"tslint-config-prettier": "^1.18.0",

rollup.config.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import dts from 'rollup-plugin-dts';
2+
import esbuild from 'rollup-plugin-esbuild';
3+
import filesize from 'rollup-plugin-filesize';
4+
import json from '@rollup/plugin-json';
5+
import resolve from '@rollup/plugin-node-resolve';
6+
import terser from '@rollup/plugin-terser';
7+
8+
const plugins = [resolve(), esbuild(), json(), terser(), filesize()];
9+
const external = /node_modules/;
10+
11+
export default [
12+
{
13+
input: 'src/index.ts',
14+
output: [
15+
{
16+
file: 'lib/cjs/index.js',
17+
format: 'cjs',
18+
sourcemap: true,
19+
},
20+
],
21+
plugins,
22+
external,
23+
},
24+
{
25+
input: 'src/index.ts',
26+
output: [
27+
{
28+
file: 'lib/esm/index.js',
29+
format: 'esm',
30+
sourcemap: true,
31+
},
32+
],
33+
plugins,
34+
external,
35+
},
36+
{
37+
input: 'src/index.ts',
38+
plugins: [dts(), json()],
39+
output: {
40+
file: 'lib/index.d.ts',
41+
format: 'es',
42+
},
43+
},
44+
];

0 commit comments

Comments
 (0)