Merge pull request #1078 from nonameShijian/PR-Branch

修复vue-sfc处理ts不正确的问题
This commit is contained in:
Spmario233 2024-03-15 12:21:09 +08:00 committed by GitHub
commit 65420ac050
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 1 deletions

View File

@ -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"`)