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

Commit

Permalink
Generate CommonJS build for Node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
realityking committed Nov 27, 2020
1 parent e309775 commit 2161fb3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
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": ">= 8"
Expand Down
33 changes: 31 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,31 @@ 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;
}

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];

0 comments on commit 2161fb3

Please sign in to comment.