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

Build CommonJS version of gavel #536

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"version": "0.0.0-semantically-released",
"description": "Validator of HTTP transactions (JavaScript implementation)",
"main": "build/index.js",
"unpkg": "build/index.umd.js",
"jsdelivr": "build/index.umd.js",
"typings": "typings.d.ts",
"engines": {
"node": ">= 10.18"
Expand Down
43 changes: 41 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ const { terser } = require('rollup-plugin-terser');

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

const dependencies = Object.keys(packageJson.dependencies);

const buildUmd = {
input: 'lib/index.js',
output: {
file: packageJson.main,
file: packageJson.unpkg,
format: 'umd',
name: 'gavel',
exports: 'named',
Expand All @@ -28,4 +30,41 @@ const buildUmd = {
]
};

module.exports = [buildUmd];
const buildCjs = {
input: 'lib/index.js',
output: {
file: packageJson.main,
format: 'cjs',
exports: 'named'
},
external: (id) => {
if (dependencies.includes(id)) {
return true;
}

// url is a built-in module and should not be bundled either
if (id === 'url') {
return true;
}

// There are some deep imports of ajv files
if (id.startsWith('ajv/')) {
return true;
}

return false;
},
plugins: [
resolve({
browser: false,

// Forbid bundling of NodeJS built-ins (i.e. "fs", "path").
// Throw when such modules are present in the bundle.
preferBuiltins: false
}),
json(),
commonjs()
]
};

module.exports = [buildUmd, buildCjs];