vite#Update TypeScript Examples
The following examples show how to use
vite#Update.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts From vite-plugin-md-preview with MIT License | 5 votes |
export function MarkdownVuePreview(options: MarkdownVuePreviewOptions = {}): PluginOption[] {
const { highlighter, shiki: shikiOptions } = options
const plugin: Plugin = {
name: 'vite:md-vue',
enforce: 'pre',
async configResolved(config) {
const shiki = await getHighlighter({
theme: 'github-light',
langs: ['vue'],
...shikiOptions,
})
transformOptions.highlighter =
highlighter ||
((code: string) => {
return shiki.codeToHtml(code, { lang: 'vue' })
})
transformOptions.root = config.root
// vuePlugin = resolvedConfig.plugins.find((p) => p.name === 'vite:vue');
},
resolveId(id) {
if (VUE_CODE_REGEXP.test(id)) {
return `${id}`
}
},
load(id) {
if (VUE_CODE_REGEXP.test(id)) {
const code = vueBlockMap.get(id)
return code
}
},
async handleHotUpdate(ctx) {
const { file, server } = ctx
const { moduleGraph, ws } = server
if (/\.md$/.test(file)) {
const updates: Update[] = []
for (const [name] of vueBlockMap) {
const mods = [...(moduleGraph.getModulesByFile(name) || new Set())]
moduleGraph.onFileChange(name)
// console.log(mods);
for (const mod of mods) {
updates.push({
type: `js-update`,
timestamp: mod.lastInvalidationTimestamp,
path: `${mod.url}`,
acceptedPath: `${mod.url}`,
})
}
}
ws.send({
type: 'update',
updates,
})
}
},
}
return [plugin]
}