Skip to content

Commit f946db0

Browse files
committed
feat: simplify build configuration with unified Rollup setup and improved TypeScript
- Unified Rollup configuration: Single rollup.config.js instead of two files - Improved TypeScript configuration: ES2020 target with better type inference - Removed redundant type annotations leveraging TypeScript's inference - Added ES module support with "type": "module" in package.json - Simplified build scripts from 8 to 4 commands - Modern TypeScript settings with declaration maps and better defaults All 70 tests passing successfully with cleaner, more maintainable configuration.
1 parent cc3a291 commit f946db0

File tree

4 files changed

+671
-151
lines changed

4 files changed

+671
-151
lines changed

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"resources"
4747
],
4848
"scripts": {
49-
"build": "rm -rf lib && rolldown -c && yarn build:types",
49+
"build": "rm -rf lib && rollup -c && yarn build:types",
5050
"build:types": "tsc --emitDeclarationOnly",
5151
"check": "biome check .",
5252
"format": "biome format --write .",
@@ -58,7 +58,7 @@
5858
"release": "semantic-release",
5959
"release:dry": "semantic-release --dry-run",
6060
"test": "NODE_OPTIONS='--experimental-vm-modules' jest",
61-
"watch": "rm -rf lib && rolldown -c --watch"
61+
"watch": "rm -rf lib && rollup -cw"
6262
},
6363
"config": {
6464
"commitizen": {
@@ -81,15 +81,21 @@
8181
},
8282
"devDependencies": {
8383
"@biomejs/biome": "^2.2.2",
84+
"@rollup/plugin-commonjs": "^28.0.6",
85+
"@rollup/plugin-json": "^6.1.0",
86+
"@rollup/plugin-node-resolve": "^16.0.1",
87+
"@rollup/plugin-terser": "^0.4.4",
8488
"@types/bson": "^4.2.4",
8589
"@types/jest": "^30.0.0",
8690
"@types/node": "^24.3.0",
8791
"@types/shelljs": "^0.8.17",
92+
"esbuild": "^0.25.9",
8893
"husky": "^9.1.7",
8994
"jest": "^30.1.3",
9095
"lint-staged": "^16.1.6",
9196
"prettier": "^3.6.2",
92-
"rolldown": "^1.0.0-beta.34",
97+
"rollup": "^4.50.0",
98+
"rollup-plugin-esbuild": "^6.2.1",
9399
"shelljs": "^0.10.0",
94100
"ts-jest": "^29.4.1",
95101
"tslib": "^2.8.1",

rollup.config.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import { readFileSync } from 'node:fs'
2+
import commonjs from '@rollup/plugin-commonjs'
3+
import json from '@rollup/plugin-json'
4+
import resolve from '@rollup/plugin-node-resolve'
5+
import terser from '@rollup/plugin-terser'
6+
import esbuild from 'rollup-plugin-esbuild'
7+
8+
const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'))
9+
10+
// External dependencies for main build
11+
const external = [
12+
...Object.keys(pkg.dependencies || {}),
13+
...Object.keys(pkg.peerDependencies || {}),
14+
]
15+
16+
// Base ESBuild config
17+
const esbuildBase = {
18+
include: /\.ts$/,
19+
exclude: /node_modules/,
20+
sourceMap: false,
21+
minify: false,
22+
target: 'es2017',
23+
tsconfig: './tsconfig.json',
24+
loaders: {
25+
'.ts': 'ts',
26+
},
27+
}
28+
29+
// Main library config (external dependencies)
30+
export const mainConfig = {
31+
input: 'src/index.ts',
32+
output: [
33+
{
34+
file: pkg.main,
35+
format: 'cjs',
36+
},
37+
{
38+
file: pkg.module,
39+
format: 'es',
40+
},
41+
],
42+
external,
43+
plugins: [esbuild(esbuildBase)],
44+
}
45+
46+
// Serverless bundled config
47+
const serverlessPlugins = [
48+
resolve({
49+
preferBuiltins: false,
50+
browser: true,
51+
}),
52+
commonjs(),
53+
json(),
54+
esbuild(esbuildBase),
55+
]
56+
57+
export const serverlessConfig = [
58+
// ESM build
59+
{
60+
input: 'src/index.serverless.ts',
61+
output: {
62+
file: 'lib/serverless.esm.js',
63+
format: 'es',
64+
},
65+
plugins: serverlessPlugins,
66+
},
67+
// ESM minified
68+
{
69+
input: 'src/index.serverless.ts',
70+
output: {
71+
file: 'lib/serverless.esm.min.js',
72+
format: 'es',
73+
},
74+
plugins: [
75+
...serverlessPlugins,
76+
terser({
77+
compress: {
78+
drop_console: true,
79+
passes: 2,
80+
},
81+
mangle: true,
82+
}),
83+
],
84+
},
85+
// CommonJS build
86+
{
87+
input: 'src/index.serverless.ts',
88+
output: {
89+
file: 'lib/serverless.cjs.js',
90+
format: 'cjs',
91+
exports: 'named',
92+
},
93+
plugins: serverlessPlugins,
94+
},
95+
// UMD build for browsers
96+
{
97+
input: 'src/index.serverless.ts',
98+
output: {
99+
file: 'lib/serverless.umd.js',
100+
format: 'umd',
101+
name: 'PhoneNumberValidator',
102+
exports: 'named',
103+
},
104+
plugins: serverlessPlugins,
105+
},
106+
// UMD minified
107+
{
108+
input: 'src/index.serverless.ts',
109+
output: {
110+
file: 'lib/serverless.umd.min.js',
111+
format: 'umd',
112+
name: 'PhoneNumberValidator',
113+
exports: 'named',
114+
},
115+
plugins: [
116+
...serverlessPlugins,
117+
terser({
118+
compress: {
119+
drop_console: true,
120+
passes: 2,
121+
},
122+
mangle: true,
123+
}),
124+
],
125+
},
126+
]
127+
128+
// Export all configs
129+
export default [mainConfig, ...serverlessConfig]

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"outDir": "./lib",
99
"rootDir": "./src",
1010
"strict": true,
11-
"moduleResolution": "bundler",
11+
"moduleResolution": "node",
1212
"esModuleInterop": true,
1313
"skipLibCheck": true,
1414
"forceConsistentCasingInFileNames": true,

0 commit comments

Comments
 (0)