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

Commit 2161fb3

Browse files
committed
Generate CommonJS build for Node.js
1 parent e309775 commit 2161fb3

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-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": ">= 8"

rollup.config.js

Lines changed: 31 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,31 @@ 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+
return false;
46+
},
47+
plugins: [
48+
resolve({
49+
browser: false,
50+
51+
// Forbid bundling of NodeJS built-ins (i.e. "fs", "path").
52+
// Throw when such modules are present in the bundle.
53+
preferBuiltins: false
54+
}),
55+
json(),
56+
commonjs()
57+
]
58+
};
59+
60+
module.exports = [buildUmd, buildCjs];

0 commit comments

Comments
 (0)