Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit bb89b49

Browse files
committed
Generate CommonJS build for Node.js
1 parent ca75f18 commit bb89b49

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"version": "0.0.0-semantically-released",
44
"description": "Validator of HTTP transactions (JavaScript implementation)",
55
"main": "build/index.js",
6+
"unpkg": "build/index.umd.js",
7+
"jsdelivr": "build/index.umd.js",
68
"typings": "typings.d.ts",
79
"engines": {
810
"node": ">= 10.18"

rollup.config.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ const { terser } = require('rollup-plugin-terser');
55

66
const packageJson = require('./package.json');
77

8+
const dependencies = Object.keys(packageJson.dependencies);
9+
810
const buildUmd = {
911
input: 'lib/index.js',
1012
output: {
11-
file: packageJson.main,
13+
file: packageJson.unpkg,
1214
format: 'umd',
1315
name: 'gavel',
1416
exports: 'named',
@@ -28,4 +30,41 @@ const buildUmd = {
2830
]
2931
};
3032

31-
module.exports = [buildUmd];
33+
const buildCjs = {
34+
input: 'lib/index.js',
35+
output: {
36+
file: packageJson.main,
37+
format: 'cjs',
38+
exports: 'named'
39+
},
40+
external: (id) => {
41+
if (dependencies.includes(id)) {
42+
return true;
43+
}
44+
45+
// url is a built-in module and should not be bundled either
46+
if (id === 'url') {
47+
return true;
48+
}
49+
50+
// There are some deep imports of ajv files
51+
if (id.startsWith('ajv/')) {
52+
return true;
53+
}
54+
55+
return false;
56+
},
57+
plugins: [
58+
resolve({
59+
browser: false,
60+
61+
// Forbid bundling of NodeJS built-ins (i.e. "fs", "path").
62+
// Throw when such modules are present in the bundle.
63+
preferBuiltins: false
64+
}),
65+
json(),
66+
commonjs()
67+
]
68+
};
69+
70+
module.exports = [buildUmd, buildCjs];

0 commit comments

Comments
 (0)