1
0
Эх сурвалжийг харах

:sparkle: support wasm.br

Van 6 жил өмнө
parent
commit
aa8f5a033d

+ 4 - 1
src/ts/markdown/lute.ts

@@ -15,6 +15,9 @@ declare const WebAssembly: {
 };
 
 export const initLute = async () => {
+    if (document.getElementById("vditorLuteJS")) {
+        return;
+    }
     if (!WebAssembly.instantiateStreaming) { // polyfill
         WebAssembly.instantiateStreaming = async (resp, importObject) => {
             const bytes = await (await resp).arrayBuffer();
@@ -24,7 +27,7 @@ export const initLute = async () => {
 
     await addScript(`http://localhost:9000/dist/js/lute/wasm_exec.js`, "vditorLuteJS");
     const go = new Go();
-    const result = await WebAssembly.instantiateStreaming(fetch(`http://localhost:9000/src/js/lute/lute.wasm`),
+    const result = await WebAssembly.instantiateStreaming(fetch(`http://localhost:9000/dist/js/lute/lute.wasm.br`),
         go.importObject);
     go.run(result.instance);
 };

+ 17 - 8
webpack.start.js

@@ -2,7 +2,7 @@
  * @fileoverview demo.
  *
  * @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
- * @version 0.1.0.0, Jan 24, 2019
+ * @version 0.2.0.0, Sep 2, 2019
  */
 
 const path = require('path')
@@ -118,21 +118,30 @@ module.exports = {
     new CopyPlugin([
       {from: 'src/images', to: 'images'},
       {from: 'src/js', to: 'js'},
-    ])
+    ]),
   ],
   devServer: {
     contentBase: path.join(__dirname, '.'),
     port: 9000,
     host: '0.0.0.0',
+    before: (app) => {
+      app.get('/dist/js/lute/lute.wasm.br', function (req, res, next) {
+        res.set({
+          'Content-Encoding': 'br',
+          'Content-Type': 'application/wasm',
+        })
+        next()
+      })
+    },
     proxy: {
       '/api': {
         target: 'http://localhost:8080',
-        pathRewrite: {'^/api' : ''}
+        pathRewrite: {'^/api': ''},
       },
       '/hacpai': {
         target: 'https://hacpai.com',
-        pathRewrite: {'^/hacpai' : ''}
-      }
-    }
-  }
-}
+        pathRewrite: {'^/hacpai': ''},
+      },
+    },
+  },
+}