Skip to content

Commit 3c510b6

Browse files
feat: Simplify build with unified Rollup config and improved TypeScript (#387)
* chore: update build * feat: add comprehensive serverless testing and lint-staged integration - Add 50+ new serverless architecture test cases covering: - Concurrent resource loading - Error handling and recovery - Locale fallback mechanisms - Performance and latency monitoring - Cache management strategies - Edge cases and validation - Integrate lint-staged with Husky for automated code quality - Run Biome checks and formatting on staged files - Ensure code consistency before commits - Update CHANGELOG with v1.6.0 features and improvements - Format scripts with Biome standards and Node.js protocol imports * chore: update build * chore: update build * chore: update build * chore: update build * chore(deps): update dependency rollup to v4.50.0 (#385) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore: update pkgs * chore: update deps and ci * feat: migrate build system to Rolldown and improve TypeScript configuration - Replace Rollup + ESBuild with Rolldown for faster, simpler builds - Remove redundant type declarations, leverage TypeScript inference - Modernize TypeScript config (ES2020 target, bundler resolution) - Simplify build scripts and configuration files - Add ES module support with "type": "module" - Reduce build dependencies from 7 packages to just Rolldown Build performance: ~90ms with Rolldown (native TypeScript support) All 70 tests passing successfully * 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. * fix: use CommonJS format for Rollup config for better compatibility - Renamed rollup.config.js to rollup.config.cjs - Removed "type": "module" from package.json - Updated build scripts to explicitly reference .cjs config file - Maintained all TypeScript improvements and unified configuration This ensures compatibility with existing Node.js environments that may not fully support ES modules while keeping the simplified build setup. * docs: update README and CHANGELOG with recent build system improvements - Document migration to unified Rollup configuration - Add build system changes section in CHANGELOG - Include Building section in README with build instructions - Document CommonJS compatibility fix for Rollup config - Note removal of redundant serverless config file --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 parent bceaaa7 commit 3c510b6

File tree

11 files changed

+321
-235
lines changed

11 files changed

+321
-235
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,22 @@
1414
- Added performance monitoring for resource loading latency
1515
- Extended test coverage for edge cases and validation
1616
- Optimized memory usage in serverless environments
17+
- Simplified build configuration with unified Rollup setup
18+
- Fixed CommonJS compatibility for Rollup config
19+
20+
### Build System Changes
21+
- Migrated from dual Rollup configuration to unified build system
22+
- Consolidated serverless and standard builds into single Rollup config
23+
- Fixed CommonJS format for Rollup config for better compatibility
24+
- Improved TypeScript configuration for cleaner output
25+
- Removed redundant rollup.config.serverless.cjs file
26+
- Streamlined build process with single build command
1727

1828
### Development
1929
- Integrated lint-staged with Husky for pre-commit hooks
2030
- Added Biome formatting and linting to staged files
2131
- Improved CI/CD pipeline with semantic-release integration
32+
- Updated dependencies and CI workflows
2233

2334
## v1.5.0
2435
### Features

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,19 @@ The library uses [tiny-lru](https://www.npmjs.com/package/tiny-lru) for high-per
334334
- **Configurable cache size** to balance memory usage and performance
335335
- **<1ms lookups** after initial data load
336336

337+
## Building
338+
339+
Build the library for both standard and serverless environments:
340+
341+
```bash
342+
yarn build
343+
```
344+
345+
This command:
346+
- Creates optimized bundles for CommonJS and ES modules
347+
- Generates TypeScript declaration files
348+
- Builds both standard and serverless versions
349+
337350
## Testing
338351

339352
```bash
File renamed without changes.

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@
4545
"resources"
4646
],
4747
"scripts": {
48-
"build": "yarn build:main && yarn build:serverless",
49-
"build:main": "rm -rf lib && rollup -c rollup.config.cjs && yarn build:types",
50-
"build:serverless": "rollup -c rollup.config.serverless.cjs",
51-
"build:types": "tsc --declaration --emitDeclarationOnly --outDir lib --declarationMap",
48+
"build": "rm -rf lib && rollup -c rollup.config.cjs && yarn build:types",
49+
"build:types": "tsc --emitDeclarationOnly",
5250
"check": "biome check .",
5351
"format": "biome format --write .",
5452
"lint": "biome lint .",
@@ -59,8 +57,7 @@
5957
"release": "semantic-release",
6058
"release:dry": "semantic-release --dry-run",
6159
"test": "jest",
62-
"watch": "rm -rf lib && rollup -cw rollup.config.cjs",
63-
"watch:serverless": "rollup -cw rollup.config.serverless.cjs"
60+
"watch": "rm -rf lib && rollup -cw rollup.config.cjs"
6461
},
6562
"config": {
6663
"commitizen": {

rolldown.config.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { readFileSync } from 'node:fs'
2+
import { defineConfig } from 'rolldown'
3+
4+
const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'))
5+
6+
// External dependencies - don't bundle these
7+
const external = [
8+
...Object.keys(pkg.dependencies || {}),
9+
...Object.keys(pkg.peerDependencies || {}),
10+
]
11+
12+
// Main library build (with external dependencies)
13+
export default defineConfig([
14+
// Main build - CommonJS and ESM
15+
{
16+
input: 'src/index.ts',
17+
output: [
18+
{
19+
file: 'lib/index.js',
20+
format: 'cjs',
21+
},
22+
{
23+
file: 'lib/index.es.js',
24+
format: 'es',
25+
},
26+
],
27+
external,
28+
resolve: {
29+
extensions: ['.ts', '.js', '.json'],
30+
},
31+
},
32+
// Serverless build - Bundle everything
33+
{
34+
input: 'src/index.serverless.ts',
35+
output: [
36+
{
37+
file: 'lib/serverless.cjs.js',
38+
format: 'cjs',
39+
exports: 'named',
40+
},
41+
{
42+
file: 'lib/serverless.esm.js',
43+
format: 'es',
44+
},
45+
{
46+
file: 'lib/serverless.umd.js',
47+
format: 'umd',
48+
name: 'PhoneNumberValidator',
49+
exports: 'named',
50+
},
51+
],
52+
resolve: {
53+
extensions: ['.ts', '.js', '.json'],
54+
},
55+
},
56+
// Serverless minified builds
57+
{
58+
input: 'src/index.serverless.ts',
59+
output: [
60+
{
61+
file: 'lib/serverless.esm.min.js',
62+
format: 'es',
63+
minify: true,
64+
},
65+
{
66+
file: 'lib/serverless.umd.min.js',
67+
format: 'umd',
68+
name: 'PhoneNumberValidator',
69+
exports: 'named',
70+
minify: true,
71+
},
72+
],
73+
resolve: {
74+
extensions: ['.ts', '.js', '.json'],
75+
},
76+
},
77+
])

rollup.config.cjs

Lines changed: 111 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1+
const { readFileSync } = require('node:fs')
12
const esbuild = require('rollup-plugin-esbuild').default
2-
const { readFileSync } = require('fs')
3+
const resolve = require('@rollup/plugin-node-resolve').default
4+
const commonjs = require('@rollup/plugin-commonjs')
5+
const json = require('@rollup/plugin-json')
6+
const terser = require('@rollup/plugin-terser').default
37

48
const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'))
59

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

rollup.config.serverless.cjs

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

0 commit comments

Comments
 (0)