diff --git a/examples/web-simple/index.html b/examples/web-simple/index.html
index 2950f3a57..ffa2e7a49 100644
--- a/examples/web-simple/index.html
+++ b/examples/web-simple/index.html
@@ -1,23 +1,150 @@
+
+
+ Concordium SDK - Web UMD Test
+
+
+
-
-
-
-
-
-
-
-
-
+
+ Concordium SDK - Web UMD Test
+
+
+
+
diff --git a/packages/rust-bindings/CHANGELOG.md b/packages/rust-bindings/CHANGELOG.md
index 33180ed1d..af4ef16ca 100644
--- a/packages/rust-bindings/CHANGELOG.md
+++ b/packages/rust-bindings/CHANGELOG.md
@@ -2,6 +2,12 @@
## Unreleased
+## 4.0.1
+
+### Fixed
+
+- An issue where the browser entrypoints of the package did not work.
+
## 4.0.0
### Breaking changes
diff --git a/packages/rust-bindings/Cargo.lock b/packages/rust-bindings/Cargo.lock
index a2b5adfcc..2806b7b5c 100644
--- a/packages/rust-bindings/Cargo.lock
+++ b/packages/rust-bindings/Cargo.lock
@@ -379,7 +379,7 @@ dependencies = [
[[package]]
name = "concordium_base"
-version = "9.0.0"
+version = "9.1.0"
dependencies = [
"anyhow",
"ark-bls12-381",
@@ -423,7 +423,7 @@ dependencies = [
[[package]]
name = "concordium_base_derive"
-version = "1.1.0-alpha.3"
+version = "1.2.0"
dependencies = [
"convert_case 0.8.0",
"darling",
diff --git a/packages/rust-bindings/package.json b/packages/rust-bindings/package.json
index 83f6809b8..9f6c5d1b2 100644
--- a/packages/rust-bindings/package.json
+++ b/packages/rust-bindings/package.json
@@ -1,6 +1,6 @@
{
"name": "@concordium/rust-bindings",
- "version": "4.0.0",
+ "version": "4.0.1",
"license": "Apache-2.0",
"type": "module",
"engines": {
@@ -28,8 +28,9 @@
"default": "./lib/dapp/node/cjs/index.cjs"
},
"browser": {
+ "module": "./lib/dapp/web/esm/index.min.js",
"types": "./lib/dapp/web/esm/index.d.ts",
- "import": "./lib/dapp/web/esm/index.js",
+ "import": "./lib/dapp/web/esm/index.min.js",
"default": "./lib/dapp/web/umd/index.min.js"
},
"default": "./lib/dapp/web/umd/index.min.js"
@@ -41,8 +42,9 @@
"default": "./lib/dapp/node/cjs/index.cjs"
},
"browser": {
+ "module": "./lib/dapp/web/esm/index.min.js",
"types": "./lib/dapp/web/esm/index.d.ts",
- "import": "./lib/dapp/web/esm/index.js",
+ "import": "./lib/dapp/web/esm/index.min.js",
"default": "./lib/dapp/web/umd/index.min.js"
},
"default": "./lib/dapp/web/umd/index.min.js"
@@ -54,8 +56,9 @@
"default": "./lib/wallet/node/cjs/index.cjs"
},
"browser": {
+ "module": "./lib/wallet/web/esm/index.min.js",
"types": "./lib/wallet/web/esm/index.d.ts",
- "import": "./lib/wallet/web/esm/index.js",
+ "import": "./lib/wallet/web/esm/index.min.js",
"default": "./lib/wallet/web/umd/index.min.js"
},
"default": "./lib/wallet/web/umd/index.min.js"
@@ -79,7 +82,7 @@
"scripts": {
"rustfmt": "cargo +nightly-2023-04-01-x86_64-unknown-linux-gnu fmt -- --color=always",
"clippy": "cargo +1.73 clippy --color=always --tests --benches -- -Dclippy::all",
- "build-web": "wasm-pack build ./packages/$0 --target web --out-dir $INIT_CWD/lib/$0/web/esm --out-name index",
+ "build-web": "wasm-pack build ./packages/$0 --target web --out-dir $INIT_CWD/lib/$0/web/esm --out-name index && tsx ./scripts/web-esm-remove-init.ts $0",
"build-node": "wasm-pack build ./packages/$0 --target nodejs --out-dir $INIT_CWD/lib/$0/node/cjs --out-name index && tsx ./scripts/fix-nodejs-ext.ts",
"build-bundler": "wasm-pack build ./packages/$0 --target bundler --out-dir $INIT_CWD/lib/$0/bundler --out-name index",
"build-all": "yarn build-web $0 && yarn build-node $0 && yarn build-bundler $0",
diff --git a/packages/rust-bindings/scripts/web-esm-remove-init.ts b/packages/rust-bindings/scripts/web-esm-remove-init.ts
new file mode 100644
index 000000000..6b4ea7256
--- /dev/null
+++ b/packages/rust-bindings/scripts/web-esm-remove-init.ts
@@ -0,0 +1,32 @@
+import * as fs from 'fs';
+import { fileURLToPath } from 'node:url';
+import * as path from 'path';
+
+/**
+ * The point of this script is to convert the ESM produced by wasm-pack to something that can be compiled by bundlers.
+ *
+ * The error happening when _not_ running the script is related to the `new URL('index_bg.wasm', import.meta.url)`, as
+ * bundlers will try to read the file at the location. The function this code snippet is embedded in, is not used in the
+ * format exposed by the rust-bindings library.
+ */
+
+const name = process.argv[2];
+if (!name) {
+ console.error('Usage: tsx scripts/web-esm-remove-init.ts ');
+ process.exit(1);
+}
+
+const __dirname = path.dirname(fileURLToPath(import.meta.url));
+const filePath = path.resolve(__dirname, '..', `lib/${name}/web/esm/index.js`);
+
+if (!fs.existsSync(filePath)) {
+ console.warn(`${filePath} not found.`);
+ process.exit(0);
+}
+const content = fs.readFileSync(filePath, 'utf8');
+const updated = content.replace("module_or_path = new URL('index_bg.wasm', import.meta.url);", '');
+if (updated !== content) {
+ fs.writeFileSync(filePath, updated);
+} else {
+ console.warn(`No line to remove in ${filePath}`);
+}
diff --git a/packages/rust-bindings/webpack.config.ts b/packages/rust-bindings/webpack.config.ts
index c00ef463a..4a17b079b 100644
--- a/packages/rust-bindings/webpack.config.ts
+++ b/packages/rust-bindings/webpack.config.ts
@@ -9,7 +9,7 @@ type WebpackEnv = Partial<{
package: string;
}>;
-function configFor(target: 'web' | 'node', pkg?: string): Configuration {
+function configFor(target: 'web' | 'node', output: 'umd' | 'esm', pkg?: string): Configuration {
const config: Configuration = {
mode: 'production',
cache: {
@@ -52,6 +52,32 @@ function configFor(target: 'web' | 'node', pkg?: string): Configuration {
},
};
+ switch (output) {
+ case 'umd': {
+ config.output = {
+ filename: `[name]/${target}/umd/index.min.js`,
+ path: resolve(__dirname, 'lib'),
+ library: { type: 'umd' },
+ publicPath: '',
+ };
+ break;
+ }
+ case 'esm': {
+ config.output = {
+ module: true,
+ filename: `[name]/${target}/esm/index.min.js`,
+ path: resolve(__dirname, 'lib'),
+ library: { type: 'module' },
+ };
+ config.experiments = {
+ outputModule: true,
+ };
+ break;
+ }
+ default:
+ throw new Error('Unsupported output');
+ }
+
if (!pkg) {
config.entry = {
dapp: resolve(__dirname, './ts-src/dapp.ts'),
@@ -66,4 +92,8 @@ function configFor(target: 'web' | 'node', pkg?: string): Configuration {
return config;
}
-export default (env: WebpackEnv) => [configFor('web', env.package), configFor('node', env.package)];
+export default (env: WebpackEnv) => [
+ configFor('web', 'umd', env.package),
+ configFor('node', 'umd', env.package),
+ configFor('web', 'esm', env.package),
+];
diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md
index 7dd83f05b..c06b60fcc 100644
--- a/packages/sdk/CHANGELOG.md
+++ b/packages/sdk/CHANGELOG.md
@@ -2,6 +2,13 @@
## Unreleased
+## 11.1.1
+
+### Fixed
+
+- An issue where WASM functionality could not be used when using the browser UMD library, orin a web context
+ without applying the bundler optimization.
+
## 11.1.0
### Added
diff --git a/packages/sdk/package.json b/packages/sdk/package.json
index 48d8aef7d..8fa726d11 100644
--- a/packages/sdk/package.json
+++ b/packages/sdk/package.json
@@ -1,6 +1,6 @@
{
"name": "@concordium/web-sdk",
- "version": "11.1.0",
+ "version": "11.1.1",
"license": "Apache-2.0",
"engines": {
"node": ">=16"
diff --git a/packages/sdk/webpack.config.ts b/packages/sdk/webpack.config.ts
index 517b665f8..c52dfef14 100644
--- a/packages/sdk/webpack.config.ts
+++ b/packages/sdk/webpack.config.ts
@@ -36,6 +36,8 @@ function configFor(target: 'web' | 'node' | 'react-native'): webpack.Configurati
},
},
module: {
+ // Don't parse the rust-bindings UMD bundles - they are self-contained with WASM initialization
+ noParse: /rust-bindings\/lib\/.*\/umd\/index\.min\.js$/,
rules: [
{
test: /\.tsx?$/,