Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
fix: fix sourcemap
Browse files Browse the repository at this point in the history
fix #4
  • Loading branch information
underfin committed Aug 6, 2020
1 parent cd5a360 commit 9d59723
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/serverPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ServerPlugin, Context } from 'vite'
import { parse, compileTemplate } from '@vue/component-compiler-utils'
import { SFCDescriptor, SFCBlock } from 'vue-template-compiler'
import {
parse,
compileTemplate,
SFCDescriptor,
SFCBlock,
} from '@vue/component-compiler-utils'
import * as fs from 'fs-extra'
import hash_sum from 'hash-sum'
import { transform } from './esbuildService'
Expand All @@ -17,6 +21,7 @@ import {
import { srcImportMap } from 'vite/dist/node/server/serverPluginVue'
import { TemplateCompileOptions } from '@vue/component-compiler-utils/lib/compileTemplate'
import { clientPublicPath } from 'vite/dist/node/server/serverPluginClient'
import { mergeSourceMap } from 'vite/dist/node/server/serverPluginSourceMap'

const vueTemplateCompiler = require('vue-template-compiler')

Expand Down Expand Up @@ -90,6 +95,7 @@ export const vuePlugin: ServerPlugin = ({
descriptor,
resolver
)
ctx.map = descriptor.script!.map
return
}

Expand Down Expand Up @@ -140,11 +146,14 @@ async function parseSFC(
code = readFile(resolver.requestToFile(srcPath))
}
if (scriptBlock.lang === 'ts') {
code = (
await transform(code, publicPath, {
loader: 'ts',
})
).code
const res = await transform(code, publicPath, {
loader: 'ts',
})
code = res.code
scriptBlock.map = mergeSourceMap(
scriptBlock.map,
JSON.parse(res.map!)
) as any
}

// rewrite export default.
Expand Down

0 comments on commit 9d59723

Please sign in to comment.