From 8386f504462473c4553c09905175775553e7472d Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 14 May 2020 18:03:04 -0400 Subject: [PATCH] fix compat with latest vite --- lib/app/index.html | 1 + src/build/bundle.ts | 9 +++++---- src/config.ts | 2 +- src/{utils/pathResolver.ts => resolver.ts} | 2 +- src/server.ts | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) rename src/{utils/pathResolver.ts => resolver.ts} (96%) diff --git a/lib/app/index.html b/lib/app/index.html index 25d70388..939a0dbc 100644 --- a/lib/app/index.html +++ b/lib/app/index.html @@ -1,6 +1,7 @@
diff --git a/src/build/bundle.ts b/src/build/bundle.ts index 852bce2b..8880e26e 100644 --- a/src/build/bundle.ts +++ b/src/build/bundle.ts @@ -1,7 +1,7 @@ import path from 'path' import slash from 'slash' import fs from 'fs-extra' -import { APP_PATH, createResolver } from '../utils/pathResolver' +import { APP_PATH, createResolver, SITE_DATA_REQUEST_PATH } from '../resolver' import { BuildOptions, ASSETS_DIR } from './build' import { SiteConfig } from '../config' import { Plugin } from 'rollup' @@ -25,12 +25,12 @@ export async function bundle( const VitePressPlugin: Plugin = { name: 'vitepress', resolveId(id) { - if (id.endsWith('.md.vue')) { + if (id === SITE_DATA_REQUEST_PATH || id.endsWith('.md.vue')) { return id } }, async load(id) { - if (id === '/@siteData') { + if (id === SITE_DATA_REQUEST_PATH) { return `export default ${JSON.stringify(JSON.stringify(config.site))}` } // compile md into vue src for .md.vue virtual files @@ -63,6 +63,7 @@ export async function bundle( } } + const appEntry = path.resolve(APP_PATH, 'index.js') // convert page files to absolute paths const pages = config.pages.map((file) => path.resolve(root, file)) @@ -83,7 +84,7 @@ export async function bundle( // this is a multi-entry build - every page is considered an entry chunk // the loading is done via filename conversion rules so that the // metadata doesn't need to be included in the main chunk. - input: [path.resolve(APP_PATH, 'index.js'), ...pages], + input: [appEntry, ...pages], // important so that each page chunk and the index export things for each // other preserveEntrySignatures: 'allow-extension', diff --git a/src/config.ts b/src/config.ts index ca362d97..1c463c56 100644 --- a/src/config.ts +++ b/src/config.ts @@ -2,7 +2,7 @@ import path from 'path' import fs from 'fs-extra' import chalk from 'chalk' import globby from 'globby' -import { createResolver, APP_PATH } from './utils/pathResolver' +import { createResolver, APP_PATH } from './resolver' import { Resolver } from 'vite' import { Header } from './markdown/plugins/header' diff --git a/src/utils/pathResolver.ts b/src/resolver.ts similarity index 96% rename from src/utils/pathResolver.ts rename to src/resolver.ts index 2b1be20e..47d46872 100644 --- a/src/utils/pathResolver.ts +++ b/src/resolver.ts @@ -2,7 +2,7 @@ import path from 'path' import { Resolver } from 'vite' // built ts files are placed into /dist -export const APP_PATH = path.join(__dirname, '../../lib/app') +export const APP_PATH = path.join(__dirname, '../lib/app') // special virtual file // we can't directly import '/@siteData' becase diff --git a/src/server.ts b/src/server.ts index 6674cbd2..b5fe12f3 100644 --- a/src/server.ts +++ b/src/server.ts @@ -7,7 +7,7 @@ import { } from 'vite' import { resolveConfig, SiteConfig, resolveSiteData } from './config' import { createMarkdownToVueRenderFn } from './markdownToVue' -import { APP_PATH, SITE_DATA_REQUEST_PATH } from './utils/pathResolver' +import { APP_PATH, SITE_DATA_REQUEST_PATH } from './resolver' const debug = require('debug')('vitepress:serve') const debugHmr = require('debug')('vitepress:hmr')