From 76043cebcbff99b2755dd281386762ab61320156 Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Tue, 23 Mar 2021 08:54:03 +0100 Subject: [PATCH] Add wasm-bindgen to Vue config (#38) --- client/web/package.json | 2 +- client/web/vue.config.js | 30 ++++++++++++++++++++++++++++++ client/web/webpack.config.js | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 client/web/vue.config.js diff --git a/client/web/package.json b/client/web/package.json index d909fd07..3600e935 100644 --- a/client/web/package.json +++ b/client/web/package.json @@ -26,7 +26,7 @@ "@vue/compiler-sfc": "^3.0.7", "@vue/eslint-config-airbnb": "^5.0.2", "@vue/eslint-config-typescript": "^5.0.2", - "@wasm-tool/wasm-pack-plugin": "^1.3.3", + "@wasm-tool/wasm-pack-plugin": "github:wasm-tool/wasm-pack-plugin", "eslint": "^6.7.2", "eslint-plugin-import": "^2.20.2", "eslint-plugin-vue": "^7.8.0", diff --git a/client/web/vue.config.js b/client/web/vue.config.js new file mode 100644 index 00000000..f8d58ef9 --- /dev/null +++ b/client/web/vue.config.js @@ -0,0 +1,30 @@ +const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin"); +const webpack = require("webpack"); +const path = require("path"); + +module.exports = { + chainWebpack: config => { + // rust wasm bindgen https://github.com/rustwasm/wasm-bindgen + config + .plugin("wasm-pack") + .use(WasmPackPlugin) + .init( + Plugin => + new Plugin({ + crateDirectory: path.resolve(__dirname, "wasm") + }) + ) + .end() + // needed for Edge browser https://rustwasm.github.io/docs/wasm-bindgen/examples/hello-world.html + .plugin("text-encoder") + .use(webpack.ProvidePlugin) + .init( + Plugin => + new Plugin({ + TextDecoder: ["text-encoding", "TextDecoder"], + TextEncoder: ["text-encoding", "TextEncoder"] + }) + ) + .end(); + } +}; diff --git a/client/web/webpack.config.js b/client/web/webpack.config.js index 3ff0804b..aa1cec6a 100644 --- a/client/web/webpack.config.js +++ b/client/web/webpack.config.js @@ -11,7 +11,7 @@ module.exports = { plugins: [ new HtmlWebpackPlugin({ title: "Graphite" }), new WasmPackPlugin({ - crateDirectory: path.resolve(__dirname, "..", "packages", "wasm-bindings"), + crateDirectory: path.resolve(__dirname, "wasm"), outDir: path.resolve(__dirname, "pkg"), }), ],