Skip to content

Commit

Permalink
feat: improve build time for testing (0xPolygonMiden#540)
Browse files Browse the repository at this point in the history
* feat: skip wasm optimizations when testing

* chore: add documentation on `testing` flag
  • Loading branch information
tomyrd authored Oct 2, 2024
1 parent 7b10611 commit dc0cc95
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/web-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"build": "rimraf dist && rollup -c rollup.config.js && cpr js/types dist && node clean.js",
"test": "node --loader ts-node/esm --loader esm ./node_modules/mocha/bin/mocha --file ./test/mocha.global.setup.mjs",
"test:logs": "DEBUG_MODE=true node --loader ts-node/esm --loader esm ./node_modules/mocha/bin/mocha --file ./test/mocha.global.setup.mjs",
"test:clean": "npm install && npm run build && node --loader ts-node/esm --loader esm ./node_modules/mocha/bin/mocha --file ./test/mocha.global.setup.mjs"
"test:clean": "npm install && MIDEN_WEB_TESTING=true npm run build && node --loader ts-node/esm --loader esm ./node_modules/mocha/bin/mocha --file ./test/mocha.global.setup.mjs"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.7",
Expand Down
9 changes: 8 additions & 1 deletion crates/web-client/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import rust from "@wasm-tool/rollup-plugin-rust";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";

// Flag that indicates if the build is meant for testing purposes.
const testing = process.env.MIDEN_WEB_TESTING === 'true';

/**
* Rollup configuration file for building a Cargo project and creating a WebAssembly (WASM) module.
* The configuration sets up two build processes:
* 1. Compiling Rust code into WASM using the @wasm-tool/rollup-plugin-rust plugin, with specific
* cargo arguments to enable WebAssembly features and set maximum memory limits.
* cargo arguments to enable WebAssembly features and set maximum memory limits. If the build is
* meant for testing, the WASM optimization level is set to 0 to improve build times, this is
* aimed at reducing the feedback loop during development.
* 2. Resolving and bundling the generated WASM module along with the main JavaScript file
* (`index.js`) into the `dist` directory.
*
Expand Down Expand Up @@ -36,6 +41,8 @@ export default [
experimental: {
typescriptDeclarationDir: "dist/crates",
},

wasmOptArgs: testing ? ["-O0"] : null,
}),
resolve(),
commonjs(),
Expand Down

0 comments on commit dc0cc95

Please sign in to comment.