From 1f85668137eee80d24aeca27f98c4d239999bba9 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Tue, 9 Feb 2021 21:42:05 -0700 Subject: [PATCH] chore: update rollup patterns --- config/rollup.cjs.config.js | 29 ++++++-------------------- config/rollup.cli.config.js | 35 ++++++-------------------------- config/rollup.iife.config.js | 5 +++-- config/rollup.iife_min.config.js | 33 ++++++------------------------ 4 files changed, 21 insertions(+), 81 deletions(-) diff --git a/config/rollup.cjs.config.js b/config/rollup.cjs.config.js index 3302940..f15b538 100644 --- a/config/rollup.cjs.config.js +++ b/config/rollup.cjs.config.js @@ -1,5 +1,7 @@ -import { nodeResolve } from "@rollup/plugin-node-resolve"; -import commonJS from "@rollup/plugin-commonjs"; +import fs from "fs"; +import { builtinModules as builtin } from "module"; + +const pkg = JSON.parse(fs.readFileSync("./package.json")); export default { input: "main.js", @@ -8,26 +10,7 @@ export default { format: "cjs", }, external: [ - "fs", - "os", - "worker_threads", - "readline", - "crypto", - "path", - "big-integer", - "wasmsnark", - "circom_runtime", - "blake2b-wasm", - - "ffjavascript", - "keccak", - "yargs", - "logplease" - ], - plugins: [ - nodeResolve({ preferBuiltins: true }), - commonJS({ - preserveSymlinks: true - }), + ...Object.keys(pkg.dependencies), + ...builtin, ] }; diff --git a/config/rollup.cli.config.js b/config/rollup.cli.config.js index 38da95c..d6d284c 100644 --- a/config/rollup.cli.config.js +++ b/config/rollup.cli.config.js @@ -1,6 +1,7 @@ -import { nodeResolve } from "@rollup/plugin-node-resolve"; -import commonJS from "@rollup/plugin-commonjs"; -import json from '@rollup/plugin-json'; +import fs from "fs"; +import { builtinModules as builtin } from "module"; + +const pkg = JSON.parse(fs.readFileSync("./package.json")); export default { input: "cli.js", @@ -10,31 +11,7 @@ export default { banner: "#! /usr/bin/env node\n", }, external: [ - "fs", - "os", - "worker_threads", - "readline", - "crypto", - "path", - "big-integer", - "wasmsnark", - "circom_runtime", - "blake2b-wasm", - - "ffjavascript", - "keccak", - "yargs", - "logplease", - ], - plugins: [ - nodeResolve({ - preferBuiltins: true, - }), - commonJS({ - preserveSymlinks: true, - include: "node_modules/**", - exclude: "node_modules/big-integer/**" - }), - json() + ...Object.keys(pkg.dependencies), + ...builtin, ] }; diff --git a/config/rollup.iife.config.js b/config/rollup.iife.config.js index 314e0db..b05a8d1 100644 --- a/config/rollup.iife.config.js +++ b/config/rollup.iife.config.js @@ -23,10 +23,11 @@ export default { os: empty, crypto: empty, readline: empty, - worker_threads: empty, }), nodeResolve({ - browser: true + browser: true, + preferBuiltins: false, + exportConditions: ['browser', 'default', 'module', 'require'] }), commonJS(), replace({ diff --git a/config/rollup.iife_min.config.js b/config/rollup.iife_min.config.js index 46b57ee..0fa4cb4 100644 --- a/config/rollup.iife_min.config.js +++ b/config/rollup.iife_min.config.js @@ -1,36 +1,15 @@ -import { nodeResolve } from "@rollup/plugin-node-resolve"; -import commonJS from "@rollup/plugin-commonjs"; -import virtual from '@rollup/plugin-virtual'; -import replace from '@rollup/plugin-replace'; +import config from './rollup.iife.config'; import { terser } from "rollup-plugin-terser"; -const empty = 'export default {}'; - export default { - input: "main.js", + ...config, output: { + ...config.output, file: "build/snarkjs.min.js", - format: "iife", - globals: { - os: "null" - }, - name: "snarkjs" + sourcemap: false, }, plugins: [ - virtual({ - fs: empty, - os: empty, - crypto: empty, - readline: empty, - worker_threads: empty, - }), - nodeResolve({ - browser: true - }), - commonJS(), - replace({ - "process.browser": !!process.env.BROWSER - }), - terser() + ...config.plugins, + terser(), ] };