Add rollup config to output CommonJS bundle

This commit is contained in:
Mark Sinclair
2023-01-17 16:32:05 +00:00
parent 5723078413
commit 317806005a
2 changed files with 32 additions and 6 deletions
+4 -6
View File
@@ -3,14 +3,11 @@
"version": "1.1.4",
"license": "Apache-2.0",
"author": "Nym Technologies SA",
"main": "dist/index.js",
"main": "dist/cjs/index.js",
"module": "dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist/worker.js",
"dist/nym_client_wasm.d.ts",
"dist/nym_client_wasm.js",
"dist/nym_client_wasm_bg.wasm",
"dist/nym_client_wasm_bg.wasm.d.ts",
"dist/**/*"
],
"exports": {
@@ -28,10 +25,11 @@
"build:dependencies:nym-client-wasm": "../nym-client-wasm/scripts/build.sh",
"prebuild": "yarn build:dependencies",
"build": "yarn build:only-this",
"build:only-this": "run-s build:worker build:tsc build:worker:move",
"build:only-this": "run-s build:worker build:tsc build:worker:move build:rollup:cjs",
"postbuild:only-this": "yarn copy:readme",
"build:tsc": "tsc",
"build:worker": "rollup src/mixnet/wasm/worker.ts -c rollup.config.mjs",
"build:rollup:cjs": "rollup -c rollup-cjs.config.mjs",
"postbuild:worker": "rm -rf dist/index.d.ts dist/coconut dist/mixnet && mkdir -p dist/mixnet/wasm",
"build:worker:move": "rm dist/mixnet/wasm/worker.js && mv dist/worker.js dist/mixnet/wasm",
"copy:readme": "cp README.md dist"
@@ -0,0 +1,28 @@
import typescript from '@rollup/plugin-typescript';
import resolve from '@rollup/plugin-node-resolve';
import { wasm } from '@rollup/plugin-wasm';
import replace from '@rollup/plugin-replace';
const extensions = [
'.js', '.jsx', '.ts', '.tsx',
];
export default {
input: 'src/index.ts',
output: {
dir: 'dist/cjs',
format: 'cjs',
},
plugins: [
resolve({ extensions }),
// this is some nasty monkey patching that removes the WASM URL (because it is handled by the `wasm` plugin)
replace({
values: { 'input = new URL(\'nym_client_wasm_bg.wasm\', import.meta.url);': 'input = undefined;' },
delimiters: ['', ''],
preventAssignment: true,
}),
// force the wasm plugin to embed the wasm bundle - this means no downstream bundlers have to worry about handling it
wasm({ maxFileSize: 10000000, targetEnv: 'browser' }),
typescript({ compilerOptions: { outDir: 'dist/cjs', declaration: false } }),
],
};