Skip to content

Commit

Permalink
fix: hmr not work in api page
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyuan0704 committed Sep 24, 2022
1 parent d3cb987 commit 44b6139
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/node/cli.ts
Expand Up @@ -12,6 +12,7 @@ cli
.alias('dev')
.action(async (root: string) => {
try {
root = resolve(root);
const createServer = async () => {
const { createDevServer } = await import(`./dev.js?t=${Date.now()}`);
const server = await createDevServer(root, async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/node/plugin-mdx/index.ts
Expand Up @@ -7,5 +7,5 @@ export async function pluginMdx(
config: SiteConfig,
isServer: boolean
): Promise<Plugin[]> {
return [await pluginMdxRollup(config, isServer), pluginMdxHMR()];
return [await pluginMdxRollup(config, isServer), pluginMdxHMR(config)];
}
9 changes: 4 additions & 5 deletions src/node/plugin-mdx/pluginMdxHmr.ts
@@ -1,15 +1,14 @@
import { MD_REGEX } from '../../node/constants';
import { Plugin, ResolvedConfig } from 'vite';
import { Plugin } from 'vite';
import { RouteService } from '../plugin-routes/RouteService';
import { SiteConfig } from 'shared/types/index';

export function pluginMdxHMR(): Plugin {
export function pluginMdxHMR(config: SiteConfig): Plugin {
let viteReactPlugin: Plugin;
let resolvedConfig: ResolvedConfig;
return {
name: 'vite-plugin-mdx-hmr',
apply: 'serve',
configResolved(config) {
resolvedConfig = config;
viteReactPlugin = config.plugins.find(
(plugin) => plugin.name === 'vite:react-babel'
) as Plugin;
Expand Down Expand Up @@ -37,7 +36,7 @@ export function pluginMdxHMR(): Plugin {
if (/\.mdx?/.test(ctx.file)) {
const routePath = RouteService.getRoutePathFromFile(
ctx.file,
resolvedConfig!.root
config.root
);
ctx.server.ws!.send({
type: 'custom',
Expand Down
2 changes: 1 addition & 1 deletion src/node/plugin-mdx/pluginMdxRollup.ts
Expand Up @@ -24,7 +24,7 @@ export async function pluginMdxRollup(
remarkPluginGFM,
// The following two plugin for frontmatter
remarkPluginFrontMatter,
remarkPluginMDXFrontMatter,
[remarkPluginMDXFrontMatter, { name: 'meta' }],
remarkPluginToc
],
rehypePlugins: [
Expand Down

0 comments on commit 44b6139

Please sign in to comment.