From 7f69b8c2a3be8b0104985f6e2cbfd5963ab5b180 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 26 May 2021 20:20:19 -0500 Subject: [PATCH] support commonjs and mjs --- fixup | 11 +++++++++++ package.json | 17 ++++++++++++----- rollup.config.js | 22 ++++++++++++++++++---- 3 files changed, 41 insertions(+), 9 deletions(-) create mode 100755 fixup diff --git a/fixup b/fixup new file mode 100755 index 0000000..f0289ed --- /dev/null +++ b/fixup @@ -0,0 +1,11 @@ +cat <dist/cjs/package.json +{ + "type": "commonjs" +} +EOF + +cat <dist/mjs/package.json +{ + "type": "module" +} +EOF diff --git a/package.json b/package.json index 02d4e2f..6b14f8f 100644 --- a/package.json +++ b/package.json @@ -23,15 +23,22 @@ "altcoin", "cryptocurrency" ], - "main": "dist/repertory-js.mjs", - "module": "dist/repertory-js.mjs", + "main": "dist/cjs/index.js", + "module": "dist/mjs/index.js", + "exports": { + ".": { + "import": "./dist/mjs/index.js", + "require": "./dist/cjs/index.js" + } + }, "files": [ - "dist" + "dist/cjs", + "dist/mjs" ], "scripts": { - "build": "rollup -c", + "build": "rollup -c && ./fixup", "test": "jest", - "prepublish": "rollup -c --silent" + "prepublish": "rollup -c --silent && ./fixup" }, "dependencies": { "int64-buffer": "^1.0.0", diff --git a/rollup.config.js b/rollup.config.js index 14b2051..963e835 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -7,7 +7,7 @@ import json from '@rollup/plugin-json'; const commonConfig = { input: 'src/index.js', output: { - name: 'repertory-js', + name: 'index', sourcemap: true, }, plugins: [ @@ -28,19 +28,33 @@ const commonConfig = { // ESM config const esmConfig = Object.assign({}, commonConfig); esmConfig.output = Object.assign({}, commonConfig.output, { - file: 'dist/repertory-js.mjs', + file: 'dist/mjs/index.js', format: 'esm', }); // ESM prod config const esmProdConfig = Object.assign({}, esmConfig); esmProdConfig.output = Object.assign({}, esmConfig.output, { - file: 'dist/repertory-js.min.mjs', + file: 'dist/mjs/index.min.js', sourcemap: false, }); esmProdConfig.plugins = [...esmConfig.plugins, terser()]; +// CJS config +const cjsConfig = Object.assign({}, commonConfig); +cjsConfig.output = Object.assign({}, commonConfig.output, { + file: 'dist/cjs/index.js', + format: 'cjs', +}); + +// CJS prod config +const cjsProdConfig = Object.assign({}, cjsConfig); +cjsProdConfig.output = Object.assign({}, cjsConfig.output, { + file: 'dist/cjs/index.min.js', + sourcemap: false, +}); +cjsProdConfig.plugins = [...cjsConfig.plugins, terser()]; let configurations = []; -configurations.push(esmConfig, esmProdConfig); +configurations.push(esmConfig, esmProdConfig, cjsConfig, cjsProdConfig); export default configurations;