feat(build): allow setting base from command line

Usage:

```sh
pnpm docs-dev -- --base /foo/
pnpm docs-build-only -- --base /foo/
pnpm docs-serve -- --base /foo/
```

Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
pull/838/head
JounQin 2 years ago committed by GitHub
parent 8cbe0f9d41
commit 295263807d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,13 +9,18 @@ import { bundle, okMark, failMark } from './bundle'
export async function build(
root: string,
buildOptions: BuildOptions & { mpa?: string } = {}
buildOptions: BuildOptions & { base?:string; mpa?: string } = {}
) {
const start = Date.now()
process.env.NODE_ENV = 'production'
const siteConfig = await resolveConfig(root, 'build', 'production')
if (buildOptions.base) {
siteConfig.site.base = buildOptions.base
delete buildOptions.base
}
if (buildOptions.mpa) {
siteConfig.mpa = true
delete buildOptions.mpa

@ -16,6 +16,7 @@ function trimChar(str: string, char: string) {
}
export interface ServeOptions {
base?: string
root?: string
port?: number
}
@ -23,7 +24,7 @@ export interface ServeOptions {
export async function serve(options: ServeOptions = {}) {
const port = options.port !== undefined ? options.port : 5000
const site = await resolveConfig(options.root, 'serve', 'production')
const base = trimChar(site?.site?.base ?? '', '/')
const base = trimChar(options?.base ?? site?.site?.base ?? '', '/')
const compress = compression()
const serve = sirv(site.outDir, {

@ -8,6 +8,11 @@ export async function createServer(
) {
const config = await resolveConfig(root)
if (serverOptions.base) {
config.site.base = serverOptions.base
delete serverOptions.base
}
return createViteServer({
root: config.srcDir,
base: config.site.base,

Loading…
Cancel
Save