scaffold build

pull/1/head
Evan You 5 years ago
parent fac49e8dbb
commit ba8de9fba7

@ -1,4 +1,25 @@
#!/usr/bin/env node
require('../dist').createServer().listen(3000, () => {
console.log('listening at http://localhost:3000')
})
const path = require('path')
const chalk = require('chalk')
const argv = require('minimist')(process.argv.slice(2))
console.log(chalk.cyan(`vitepress v${require('../package.json').version}`))
const command = argv._[0]
if (!command || command === 'dev') {
const port = argv.port || 3000
const root = command === 'dev' && argv._[1]
if (root) {
argv.root = root
}
require('../dist').createServer(argv).listen(port, () => {
console.log(`listening at http://localhost:${port}`)
})
} else if (command === 'build') {
require('../dist').build(argv).catch(err => {
console.error(`build error: `, err)
})
} else {
console.log(chalk.red(`unknown command "${command}".`))
}

@ -27,6 +27,7 @@
"markdown-it-container": "^2.0.0",
"markdown-it-emoji": "^1.4.0",
"markdown-it-table-of-contents": "^0.4.4",
"minimist": "^1.2.5",
"prismjs": "^1.20.0",
"vite": "^0.6.0"
},

@ -0,0 +1,6 @@
import { buildClient } from './buildClient'
import { BuildOptions } from 'vite'
export async function build(options: BuildOptions = {}) {
await buildClient(options)
}

@ -0,0 +1,8 @@
import { build, BuildOptions } from 'vite'
export async function buildClient(options: BuildOptions) {
await build({
...options,
cdn: false
})
}

@ -1 +1,2 @@
export * from './server/server'
export * from './build/build'

@ -1,5 +1,10 @@
import path from 'path'
import { createServer as createViteServer, cachedRead, Plugin } from 'vite'
import {
createServer as createViteServer,
cachedRead,
Plugin,
ServerConfig
} from 'vite'
import { createMarkdownToVueRenderFn } from '../markdown/markdownToVue'
import { VitePressResolver, THEME_PATH, APP_PATH } from './resolver'
@ -56,8 +61,9 @@ const VitePressPlugin: Plugin = ({ app, root, watcher, resolver }) => {
})
}
export function createServer() {
export function createServer(options: ServerConfig = {}) {
return createViteServer({
...options,
plugins: [VitePressPlugin],
resolvers: [VitePressResolver]
})

Loading…
Cancel
Save