Skip to content

Commit ef4f43b

Browse files
committed
Set up Rollup build configuration for TypeScript
- Added rollup.config.js with three output formats: * CJS: cjs/UrlUtils.js (CommonJS for Node.js) * ESM: es/UrlUtils.js (ES Modules with sourcemap) * UMD: umd/url-utils.min.js (Browser bundle, minified) - Added build scripts to package.json: * build: Compile TypeScript and generate type definitions * pretest: Build before running tests * prepare: Build before publish - Updated files field to include build output directories
1 parent ad47f9d commit ef4f43b

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

packages/url-utils/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@
1111
"main": "index.js",
1212
"scripts": {
1313
"dev": "echo \"Implement me!\"",
14+
"pretest": "yarn build",
1415
"test": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura --reporter html mocha './test/**/*.test.js'",
16+
"build": "rollup -c && tsc --declaration --emitDeclarationOnly --declarationDir ./types",
1517
"lint": "eslint . --ext .js --cache",
18+
"prepare": "NODE_ENV=production yarn build",
1619
"posttest": "yarn lint"
1720
},
1821
"files": [
19-
"lib/",
22+
"src/",
23+
"cjs/",
24+
"es/",
25+
"umd/",
26+
"types/",
2027
"index.js"
2128
],
2229
"publishConfig": {
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* eslint-env node */
2+
import typescript from '@rollup/plugin-typescript';
3+
import commonjs from 'rollup-plugin-commonjs';
4+
import resolve from 'rollup-plugin-node-resolve';
5+
import json from '@rollup/plugin-json';
6+
import {terser} from 'rollup-plugin-terser';
7+
8+
export default [
9+
// Node build.
10+
// No transpilation or bundling other than conversion from es modules to cjs
11+
{
12+
input: 'src/UrlUtils.ts',
13+
output: {
14+
file: 'cjs/UrlUtils.js',
15+
format: 'cjs',
16+
interop: false
17+
},
18+
plugins: [
19+
typescript(),
20+
commonjs({
21+
include: ['node_modules/**', '../../node_modules/**']
22+
})
23+
]
24+
},
25+
26+
// ES module build
27+
// Transpiles to es version supported by preset-env's default browsers list,
28+
// bundles all necessary dependencies and polyfills
29+
{
30+
input: 'src/UrlUtils.ts',
31+
output: [{
32+
file: 'es/UrlUtils.js',
33+
format: 'es',
34+
sourcemap: true
35+
}],
36+
plugins: [
37+
resolve({
38+
browser: true
39+
}),
40+
json(),
41+
typescript(),
42+
commonjs({
43+
include: ['node_modules/**', '../../node_modules/**']
44+
})
45+
]
46+
},
47+
48+
// Standalone UMD browser build (minified).
49+
// Transpiles to es version supported by preset-env's default browsers list,
50+
// bundles all dependencies and polyfills.
51+
{
52+
input: 'src/UrlUtils.ts',
53+
output: {
54+
file: 'umd/url-utils.min.js',
55+
format: 'umd',
56+
name: 'GhostUrlUtils',
57+
sourcemap: true
58+
},
59+
plugins: [
60+
resolve({
61+
browser: true
62+
}),
63+
json(),
64+
typescript(),
65+
commonjs({
66+
include: ['node_modules/**', '../../node_modules/**']
67+
}),
68+
terser()
69+
]
70+
}
71+
];

0 commit comments

Comments
 (0)