From f91ce7e68e30ae79e0e5eb9b749c36e11f383da5 Mon Sep 17 00:00:00 2001 From: LOSSES Don <1384036+Losses@users.noreply.github.com> Date: Sat, 10 May 2025 10:09:49 +0800 Subject: [PATCH 1/4] fix: The default template is no longer usable --- template/{js => }/index.js | 0 template/package.json | 10 +++++----- template/webpack.config.js | 41 ++++++++++++++++++++++++++++---------- 3 files changed, 36 insertions(+), 15 deletions(-) rename template/{js => }/index.js (100%) diff --git a/template/js/index.js b/template/index.js similarity index 100% rename from template/js/index.js rename to template/index.js diff --git a/template/package.json b/template/package.json index 26c4708..e551233 100644 --- a/template/package.json +++ b/template/package.json @@ -9,10 +9,10 @@ }, "devDependencies": { "@wasm-tool/wasm-pack-plugin": "^1.1.0", - "copy-webpack-plugin": "^5.0.3", - "webpack": "^4.42.0", - "webpack-cli": "^3.3.3", - "webpack-dev-server": "^3.7.1", - "rimraf": "^3.0.0" + "copy-webpack-plugin": "^13.0.0", + "webpack": "^5.99.8", + "webpack-cli": "^6.0.1", + "webpack-dev-server": "^5.2.1", + "rimraf": "^6.0.1" } } diff --git a/template/webpack.config.js b/template/webpack.config.js index d35da09..1ba21f4 100644 --- a/template/webpack.config.js +++ b/template/webpack.config.js @@ -1,5 +1,5 @@ -const path = require("path"); -const CopyPlugin = require("copy-webpack-plugin"); +const path = require("node:path"); +const CopyWebpackPlugin = require("copy-webpack-plugin"); const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin"); const dist = path.resolve(__dirname, "dist"); @@ -7,22 +7,43 @@ const dist = path.resolve(__dirname, "dist"); module.exports = { mode: "production", entry: { - index: "./js/index.js" + index: "./index.js", }, output: { path: dist, - filename: "[name].js" + filename: "[name].js", }, devServer: { - contentBase: dist, + static: { + directory: dist, + }, + }, + performance: { + hints: "warning", + maxAssetSize: 500 * 1024, + maxEntrypointSize: 500 * 1024, + assetFilter: (assetFilename) => { + return !/\.wasm$/.test(assetFilename); + }, }, plugins: [ - new CopyPlugin([ - path.resolve(__dirname, "static") - ]), + new CopyWebpackPlugin({ + patterns: ["static/index.html"], + }), new WasmPackPlugin({ - crateDirectory: __dirname, + crateDirectory: path.resolve(__dirname, ".."), }), - ] + ], + module: { + rules: [ + { + test: /\.wasm$/, + type: "webassembly/async", + }, + ], + }, + experiments: { + asyncWebAssembly: true, + }, }; From 52edf6b5175ce68939a1eaf2a618d7d2a0e3a6c2 Mon Sep 17 00:00:00 2001 From: LOSSES Don <1384036+Losses@users.noreply.github.com> Date: Sat, 10 May 2025 10:13:02 +0800 Subject: [PATCH 2/4] chore: Change webpack dev server to developmental mode for better development experience --- template/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/package.json b/template/package.json index e551233..5073ece 100644 --- a/template/package.json +++ b/template/package.json @@ -4,7 +4,7 @@ "version": "0.1.0", "scripts": { "build": "rimraf dist pkg && webpack", - "start": "rimraf dist pkg && webpack-dev-server --open -d", + "start": "rimraf dist pkg && webpack-dev-server --mode=development", "test": "cargo test && wasm-pack test --headless" }, "devDependencies": { From 240c9c858468eac523dd4bed6ecf9a591ba0eb58 Mon Sep 17 00:00:00 2001 From: LOSSES Don <1384036+Losses@users.noreply.github.com> Date: Sat, 10 May 2025 10:17:39 +0800 Subject: [PATCH 3/4] chore: Align the default directory structure --- template/{ => js}/index.js | 0 template/webpack.config.js | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename template/{ => js}/index.js (100%) diff --git a/template/index.js b/template/js/index.js similarity index 100% rename from template/index.js rename to template/js/index.js diff --git a/template/webpack.config.js b/template/webpack.config.js index 1ba21f4..e154eb9 100644 --- a/template/webpack.config.js +++ b/template/webpack.config.js @@ -7,7 +7,7 @@ const dist = path.resolve(__dirname, "dist"); module.exports = { mode: "production", entry: { - index: "./index.js", + index: "./js/index.js", }, output: { path: dist, @@ -32,7 +32,7 @@ module.exports = { }), new WasmPackPlugin({ - crateDirectory: path.resolve(__dirname, ".."), + crateDirectory: __dirname, }), ], module: { From 639465d17efda1451ff677cbebbeeea77f825457 Mon Sep 17 00:00:00 2001 From: LOSSES Don <1384036+Losses@users.noreply.github.com> Date: Sat, 10 May 2025 10:18:32 +0800 Subject: [PATCH 4/4] chore: Align the static directory config --- template/webpack.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/webpack.config.js b/template/webpack.config.js index e154eb9..eb6026c 100644 --- a/template/webpack.config.js +++ b/template/webpack.config.js @@ -28,7 +28,7 @@ module.exports = { }, plugins: [ new CopyWebpackPlugin({ - patterns: ["static/index.html"], + patterns: [path.resolve(__dirname, "static")], }), new WasmPackPlugin({