fix compat with latest vite

pull/18/head
Evan You 5 years ago
parent f273aa60fa
commit 8386f50446

@ -1,6 +1,7 @@
<div id="app"></div> <div id="app"></div>
<script> <script>
window.__DEV__ = true window.__DEV__ = true
window.__BASE__ = '/' // TODO handle base!
window.process = { env: { NODE_ENV: 'development'} } window.process = { env: { NODE_ENV: 'development'} }
</script> </script>
<script type="module" src="/@app/index.js"></script> <script type="module" src="/@app/index.js"></script>

@ -1,7 +1,7 @@
import path from 'path' import path from 'path'
import slash from 'slash' import slash from 'slash'
import fs from 'fs-extra' 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 { BuildOptions, ASSETS_DIR } from './build'
import { SiteConfig } from '../config' import { SiteConfig } from '../config'
import { Plugin } from 'rollup' import { Plugin } from 'rollup'
@ -25,12 +25,12 @@ export async function bundle(
const VitePressPlugin: Plugin = { const VitePressPlugin: Plugin = {
name: 'vitepress', name: 'vitepress',
resolveId(id) { resolveId(id) {
if (id.endsWith('.md.vue')) { if (id === SITE_DATA_REQUEST_PATH || id.endsWith('.md.vue')) {
return id return id
} }
}, },
async load(id) { async load(id) {
if (id === '/@siteData') { if (id === SITE_DATA_REQUEST_PATH) {
return `export default ${JSON.stringify(JSON.stringify(config.site))}` return `export default ${JSON.stringify(JSON.stringify(config.site))}`
} }
// compile md into vue src for .md.vue virtual files // 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 // convert page files to absolute paths
const pages = config.pages.map((file) => path.resolve(root, file)) 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 // this is a multi-entry build - every page is considered an entry chunk
// the loading is done via filename conversion rules so that the // the loading is done via filename conversion rules so that the
// metadata doesn't need to be included in the main chunk. // 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 // important so that each page chunk and the index export things for each
// other // other
preserveEntrySignatures: 'allow-extension', preserveEntrySignatures: 'allow-extension',

@ -2,7 +2,7 @@ import path from 'path'
import fs from 'fs-extra' import fs from 'fs-extra'
import chalk from 'chalk' import chalk from 'chalk'
import globby from 'globby' import globby from 'globby'
import { createResolver, APP_PATH } from './utils/pathResolver' import { createResolver, APP_PATH } from './resolver'
import { Resolver } from 'vite' import { Resolver } from 'vite'
import { Header } from './markdown/plugins/header' import { Header } from './markdown/plugins/header'

@ -2,7 +2,7 @@ import path from 'path'
import { Resolver } from 'vite' import { Resolver } from 'vite'
// built ts files are placed into /dist // 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 // special virtual file
// we can't directly import '/@siteData' becase // we can't directly import '/@siteData' becase

@ -7,7 +7,7 @@ import {
} from 'vite' } from 'vite'
import { resolveConfig, SiteConfig, resolveSiteData } from './config' import { resolveConfig, SiteConfig, resolveSiteData } from './config'
import { createMarkdownToVueRenderFn } from './markdownToVue' 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 debug = require('debug')('vitepress:serve')
const debugHmr = require('debug')('vitepress:hmr') const debugHmr = require('debug')('vitepress:hmr')

Loading…
Cancel
Save