Skip to content

Commit 979219b

Browse files
committed
feat: Refine CJS/ESM build configuration for browser SDK.
1 parent 48cac54 commit 979219b

File tree

4 files changed

+41
-78
lines changed

4 files changed

+41
-78
lines changed

packages/sdk/browser/package.json

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,31 @@
1717
"sdk"
1818
],
1919
"exports": {
20-
"types": "./dist/src/index.d.ts",
21-
"require": "./dist/index.cjs.js",
22-
"import": "./dist/index.es.js"
20+
"require": {
21+
"types": "./dist/index.d.cts",
22+
"default": "./dist/index.cjs"
23+
},
24+
"import": {
25+
"types": "./dist/esm/index.d.ts",
26+
"default": "./dist/esm/index.js"
27+
}
2328
},
2429
"type": "module",
2530
"files": [
2631
"dist"
2732
],
2833
"scripts": {
2934
"clean": "rimraf dist",
30-
"build": "tsc --noEmit && rollup -c rollup.config.js",
35+
"build": "tsup",
3136
"lint": "eslint . --ext .ts,.tsx",
3237
"prettier": "prettier --write '**/*.@(js|ts|tsx|json|css)' --ignore-path ../../../.prettierignore",
3338
"test": "npx jest --runInBand",
3439
"coverage": "yarn test --coverage",
3540
"check": "yarn prettier && yarn lint && yarn build && yarn test"
3641
},
37-
"dependencies": {
38-
"@launchdarkly/js-client-sdk-common": "1.10.0"
39-
},
4042
"devDependencies": {
43+
"@launchdarkly/js-client-sdk-common": "1.10.0",
4144
"@jest/globals": "^29.7.0",
42-
"@rollup/plugin-commonjs": "^25.0.0",
43-
"@rollup/plugin-json": "^6.1.0",
44-
"@rollup/plugin-node-resolve": "^15.0.2",
45-
"@rollup/plugin-terser": "^0.4.3",
46-
"@rollup/plugin-typescript": "^11.1.1",
4745
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
4846
"@types/jest": "^29.5.11",
4947
"@typescript-eslint/eslint-plugin": "^6.20.0",
@@ -59,9 +57,8 @@
5957
"jest-environment-jsdom": "^29.7.0",
6058
"prettier": "^3.0.0",
6159
"rimraf": "^5.0.5",
62-
"rollup": "^3.23.0",
63-
"rollup-plugin-visualizer": "^5.12.0",
6460
"ts-jest": "^29.1.1",
61+
"tsup": "^8.3.5",
6562
"typedoc": "0.25.0",
6663
"typescript": "^5.5.3"
6764
}

packages/sdk/browser/rollup.config.js

Lines changed: 0 additions & 58 deletions
This file was deleted.

packages/sdk/browser/tsconfig.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,27 @@
88
"moduleResolution": "node",
99
"noImplicitOverride": true,
1010
"resolveJsonModule": true,
11-
// Uses "." so it can load package.json.
12-
"rootDir": ".",
11+
"rootDir": "src",
1312
"outDir": "dist",
1413
"skipLibCheck": true,
15-
// enables importers to jump to source
16-
"sourceMap": true,
14+
"sourceMap": false,
1715
"strict": true,
1816
"stripInternal": true,
1917
"target": "ES2017",
2018
"types": ["node", "jest"],
2119
"allowJs": true
2220
},
21+
"include": ["src"],
2322
"exclude": [
2423
"vite.config.ts",
2524
"__tests__",
2625
"dist",
2726
"docs",
2827
"example",
2928
"node_modules",
30-
"contract-tests",
3129
"babel.config.js",
32-
"jestSetupFile.ts",
30+
"setup-jest.js",
31+
"rollup.config.js",
3332
"**/*.test.ts*"
3433
]
3534
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// It is a dev dependency and the linter doesn't understand.
2+
// eslint-disable-next-line import/no-extraneous-dependencies
3+
import { defineConfig } from 'tsup';
4+
5+
export default defineConfig({
6+
minify: 'terser',
7+
terserOptions: {
8+
mangle: {
9+
properties: {
10+
// Mangle class properties which start with an underscore.
11+
regex: /^_/,
12+
// Do not mangle '_meta', because this is part of our JSON
13+
// data model.
14+
reserved: ['_meta'],
15+
},
16+
},
17+
},
18+
format: ['esm', 'cjs'],
19+
entry: ['src/index.ts'],
20+
splitting: false,
21+
sourcemap: false,
22+
clean: true,
23+
dts: true,
24+
treeshake: true,
25+
});

0 commit comments

Comments
 (0)