From 25d9048506c32b41ec0192f383fa13e81d066f96 Mon Sep 17 00:00:00 2001 From: Jesse-Ma <24167796@qq.com> Date: Tue, 7 Mar 2023 17:55:05 +0800 Subject: [PATCH] =?UTF-8?q?wasm=20=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +-- public/index.html | 13 ++++++++++++- src/libs/secret.js | 15 +++++++++------ src/views/EditNote.vue | 2 ++ vue.config.js | 11 +++++++---- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 7ca1e10..06efb07 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,7 @@ "vue": "^2.7.14", "vue-axios": "^3.5.2", "vue-i18n": "^8.28.2", - "vue-router": "^3.5.4", - "wasm-flate": "1.0.2-bundler" + "vue-router": "^3.6.5" }, "devDependencies": { "@babel/core": "^7.12.16", diff --git a/public/index.html b/public/index.html index 3abc3db..497f4d4 100644 --- a/public/index.html +++ b/public/index.html @@ -26,7 +26,7 @@ - @@ -44,10 +44,19 @@ type="text/javascript"> + + + +
@@ -58,6 +67,8 @@ if (!!window.ActiveXObject || "ActiveXObject" in window) { document.querySelector('#noie').style.display = 'block'; } + + diff --git a/src/libs/secret.js b/src/libs/secret.js index 2079ceb..35e39ab 100644 --- a/src/libs/secret.js +++ b/src/libs/secret.js @@ -1,7 +1,8 @@ import CryptoJS from "crypto-js"; import pako from "pako"; -import {gzip_encode_raw,gzip_decode_raw} from 'wasm-flate'; +//import {gzip_encode_raw,gzip_decode_raw} from 'wasm-flate'; +const wasmFlate = window.wasm_bindgen; /** * @word 要加密的内容 @@ -80,16 +81,18 @@ export function noteZip(text) { } function zip(data){ - if(gzip_encode_raw){ - return gzip_encode_raw(data); - } + if(wasmFlate.__wbindgen_wasm_module){ + return wasmFlate.gzip_encode_raw(data); + } + return pako.gzip(data); } function unzip(data){ - if(gzip_decode_raw){ - return gzip_decode_raw(data); + if(wasmFlate.__wbindgen_wasm_module){ + return wasmFlate.gzip_decode_raw(data); } + return pako.ungzip(data); } diff --git a/src/views/EditNote.vue b/src/views/EditNote.vue index 2fbe813..17b249c 100644 --- a/src/views/EditNote.vue +++ b/src/views/EditNote.vue @@ -295,6 +295,8 @@ export default { this.bindCtrlAllEvent(); this.bindToTopEvent(); + + window.wasm_bindgen(window.wasm_flate_bg_path); }, mounted() { const myObserver = new ResizeObserver(entries => { diff --git a/vue.config.js b/vue.config.js index d0d1f72..f24bc72 100644 --- a/vue.config.js +++ b/vue.config.js @@ -6,7 +6,10 @@ module.exports = defineConfig({ assetsDir: 'static', productionSourceMap: false, + configureWebpack: (config) => { + config.experiments = { asyncWebAssembly: true,syncWebAssembly:true } + config.externals = { 'vue': 'Vue', @@ -20,8 +23,7 @@ module.exports = defineConfig({ "iview": 'ViewUI', "file-saver": 'saveAs', "clipboard": "ClipboardJS", - "vue-i18n": "VueI18n", - + "vue-i18n": "VueI18n" }; // 为生产环境修改配置 @@ -44,7 +46,7 @@ module.exports = defineConfig({ new CompressionPlugin({ algorithm: "gzip", // 使用gzip压缩 - test: /\.js$|\.html$|\.png$|\.jpg$|\.svg$|\.css$/, // 匹配文件名 + test: /\.js$|\.html$|\.png$|\.jpg$|\.svg$|\.wasm$|\.css$/, // 匹配文件名 filename: "[path][base].gz[query]", // 压缩后的文件名(保持原文件名,后缀加.gz) minRatio: 1, // 压缩率小于1才会压缩 threshold: 5120, // 对超过10k的数据压缩 @@ -63,7 +65,8 @@ module.exports = defineConfig({ devServer: { proxy: { "/note": { - target: "http://127.0.0.1:10000/", // 后台接口域名 +// target: "https://flagnote.com/", // 后台接口域名 + target: "http://localhost:10000/", // 后台接口域名 secure: false, // 如果是https接口,需要配置这个参数 changeOrigin: true, //是否跨域 pathRewrite: {