wip: make build pass

pull/198/head
Evan You 4 years ago
parent 04ed45d250
commit b50a2dffc4

@ -86,7 +86,7 @@
"prismjs": "^1.20.0", "prismjs": "^1.20.0",
"sirv": "^1.0.10", "sirv": "^1.0.10",
"slash": "^3.0.0", "slash": "^3.0.0",
"vite": "^2.0.0-alpha.1", "vite": "^2.0.0-alpha.2",
"vue": "^3.0.4" "vue": "^3.0.4"
}, },
"devDependencies": { "devDependencies": {

@ -24,3 +24,6 @@ import { ComponentOptions } from 'vue'
import _Debug from './components/Debug.vue' import _Debug from './components/Debug.vue'
const Debug = _Debug as ComponentOptions const Debug = _Debug as ComponentOptions
export { Debug } export { Debug }
// default theme
export { default as DefaultTheme } from '../theme-default'

@ -1,7 +1,8 @@
import path from 'path' import path from 'path'
import { AliasOptions } from 'vite' import { Alias, AliasOptions } from 'vite'
import { UserConfig } from './config' import { UserConfig } from './config'
const PKG_ROOT = path.join(__dirname, '../../')
export const APP_PATH = path.join(__dirname, '../client/app') export const APP_PATH = path.join(__dirname, '../client/app')
export const SHARED_PATH = path.join(__dirname, '../client/shared') export const SHARED_PATH = path.join(__dirname, '../client/shared')
export const DEFAULT_THEME_PATH = path.join( export const DEFAULT_THEME_PATH = path.join(
@ -20,17 +21,47 @@ export const SITE_DATA_REQUEST_PATH = '/' + SITE_DATA_ID
// so that we can resolve custom requests that start with /@app or /@theme // so that we can resolve custom requests that start with /@app or /@theme
// we also need to map file paths back to their public served paths so that // we also need to map file paths back to their public served paths so that
// vite HMR can send the correct update notifications to the client. // vite HMR can send the correct update notifications to the client.
export function createAlias( export function resolveAliases(
root: string,
themeDir: string, themeDir: string,
userConfig: UserConfig userConfig: UserConfig
): AliasOptions { ): AliasOptions {
return { const paths: Record<string, string> = {
...userConfig.alias, ...userConfig.alias,
'/@app': APP_PATH, '/@app': APP_PATH,
'/@theme': themeDir, '/@theme': themeDir,
'/@default-theme': DEFAULT_THEME_PATH, '/@default-theme': DEFAULT_THEME_PATH,
'/@shared': SHARED_PATH, '/@shared': SHARED_PATH,
vitepress: `${APP_PATH}/exports.js`,
[SITE_DATA_ID]: SITE_DATA_REQUEST_PATH [SITE_DATA_ID]: SITE_DATA_REQUEST_PATH
} }
const aliases: Alias[] = [
...Object.keys(paths).map((p) => ({
find: p,
replacement: paths[p]
})),
{ find: /^vitepress$/, replacement: `${APP_PATH}/exports.js` }
]
let isLinked = false
try {
require.resolve('vitepress', { paths: [root] })
} catch (e) {
isLinked = true
}
if (isLinked) {
// aliases for local linked development
aliases.push(
{ find: /^vitepress\//, replacement: PKG_ROOT + '/' },
{
find: /^vue$/,
replacement: require.resolve(
'@vue/runtime-dom/dist/runtime-dom.esm-bundler.js'
)
}
)
}
return aliases
} }

@ -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 { createAlias, APP_PATH, DEFAULT_THEME_PATH } from './alias' import { resolveAliases, APP_PATH, DEFAULT_THEME_PATH } from './alias'
import { SiteData, HeadConfig, LocaleConfig } from '../../types/shared' import { SiteData, HeadConfig, LocaleConfig } from '../../types/shared'
import { MarkdownOptions } from './markdown/markdown' import { MarkdownOptions } from './markdown/markdown'
import { AliasOptions } from 'vite' import { AliasOptions } from 'vite'
@ -59,7 +59,7 @@ export async function resolveConfig(
outDir: resolve(root, 'dist'), outDir: resolve(root, 'dist'),
tempDir: path.resolve(APP_PATH, 'temp'), tempDir: path.resolve(APP_PATH, 'temp'),
markdown: userConfig.markdown, markdown: userConfig.markdown,
aliases: createAlias(themeDir, userConfig) aliases: resolveAliases(root, themeDir, userConfig)
} }
return config return config

@ -5939,10 +5939,10 @@ verror@1.10.0:
core-util-is "1.0.2" core-util-is "1.0.2"
extsprintf "^1.2.0" extsprintf "^1.2.0"
vite@^2.0.0-alpha.1: vite@^2.0.0-alpha.2:
version "2.0.0-alpha.1" version "2.0.0-alpha.2"
resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.0-alpha.1.tgz#bc184f7c0b06e9142dd0b5e49a0a7cbbb79989d2" resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.0-alpha.2.tgz#ef03271c0dc9d301076fbeed01b48849f89722a1"
integrity sha512-bmpgZuTQo3n4jO/jsdiNZRZSIUZeISkCW9c99FV+lnwukA1DFri3ix9w7x439xYQnqDAzONPMfKHtR1zdmyDag== integrity sha512-iGTlNzH4uskwEu32XmDk0i9dFRUax9ZHjL+5DXbX/cisNYQC35KhLaiLKwdL3iSu8fFYc3nd8sfKfCndJxL3AQ==
dependencies: dependencies:
esbuild "^0.8.26" esbuild "^0.8.26"
postcss "^8.2.1" postcss "^8.2.1"

Loading…
Cancel
Save