diff --git a/packages/plugin-vue/src/handleHotUpdate.ts b/packages/plugin-vue/src/handleHotUpdate.ts index 76760369..32da6125 100644 --- a/packages/plugin-vue/src/handleHotUpdate.ts +++ b/packages/plugin-vue/src/handleHotUpdate.ts @@ -7,19 +7,18 @@ import { } from './utils/descriptorCache' import { getResolvedScript, setResolvedScript } from './script' import { ModuleNode, HmrContext } from 'vite' +import { ResolvedOptions } from '.' const debug = _debug('vite:hmr') /** * Vite-specific HMR handling */ -export async function handleHotUpdate({ - file, - modules, - read, - server -}: HmrContext): Promise { - const prevDescriptor = getDescriptor(file, server.config.root, false, false) +export async function handleHotUpdate( + { file, modules, read, server }: HmrContext, + options: ResolvedOptions +): Promise { + const prevDescriptor = getDescriptor(file, options, false) if (!prevDescriptor) { // file hasn't been requested yet (e.g. async component) return @@ -28,12 +27,7 @@ export async function handleHotUpdate({ setPrevDescriptor(file, prevDescriptor) const content = await read() - const { descriptor } = createDescriptor( - file, - content, - server.config.root, - false - ) + const { descriptor } = createDescriptor(file, content, options) let needRerender = false const affectedModules = new Set() diff --git a/packages/plugin-vue/src/index.ts b/packages/plugin-vue/src/index.ts index 95fb8a7f..c1504cc7 100644 --- a/packages/plugin-vue/src/index.ts +++ b/packages/plugin-vue/src/index.ts @@ -80,6 +80,7 @@ export interface Options { export interface ResolvedOptions extends Options { root: string + sourceMap: boolean devServer?: ViteDevServer } @@ -115,7 +116,8 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { exclude, customElement, refTransform, - root: process.cwd() + root: process.cwd(), + sourceMap: true } return { @@ -125,7 +127,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { if (!filter(ctx.file)) { return } - return handleHotUpdate(ctx) + return handleHotUpdate(ctx, options) }, config(config) { @@ -145,6 +147,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { options = { ...options, root: config.root, + sourceMap: config.command === 'build' ? !!config.build.sourcemap : true, isProduction: config.isProduction } }, @@ -167,11 +170,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { if (query.src) { return fs.readFileSync(filename, 'utf-8') } - const descriptor = getDescriptor( - filename, - options.root, - options.isProduction - )! + const descriptor = getDescriptor(filename, options)! let block: SFCBlock | null | undefined if (query.type === 'script') { // handle +