From 84f19833498595038b6e9f5775e8ca183cc54123 Mon Sep 17 00:00:00 2001 From: nonameShijian <2954700422@qq.com> Date: Thu, 14 Mar 2024 21:37:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dvue-sfc=E5=A4=84=E7=90=86ts?= =?UTF-8?q?=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service-worker.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/service-worker.js b/service-worker.js index 43efb15ee..1bfd5f86d 100644 --- a/service-worker.js +++ b/service-worker.js @@ -114,7 +114,13 @@ self.addEventListener('fetch', event => { vueFileMap.set( request.url + '?type=script', // 重写 default - sfc.rewriteDefault(script.content, "__sfc_main__") + sfc.rewriteDefault(script.attrs && script.attrs.lang == 'ts' ? ts.transpile(script.content, { + module: ts.ModuleKind.ES2015, + target: ts.ScriptTarget.ES2019, + inlineSourceMap: true, + resolveJsonModule: true, + esModuleInterop: true, + }, request.url + '?type=script') : script.content, "__sfc_main__") .replace(`const __sfc_main__`, `export const __sfc_main__`) // import vue重新指向 .replaceAll(`from "vue"`, `from "/game/vue.esm-browser.js"`)