vitepress icon indicating copy to clipboard operation
vitepress copied to clipboard

custom `outDir` resolves from `root` instead of `pwd`, is this expected?(Not to me at least)

Open JounQin opened this issue 3 years ago • 6 comments

Describe the bug

As title

Reproduction

N/A

Expected behavior

Resolve outDir from pwd instead of root

System Info

System:
    OS: macOS 13.0
    CPU: (10) arm64 Apple M1 Max
    Memory: 6.09 GB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.1 - ~/Library/Caches/fnm_multishells/985_1655820447617/bin/node
    Yarn: 1.22.19 - ~/Library/Caches/fnm_multishells/985_1655820447617/bin/yarn
    npm: 8.12.1 - ~/Library/Caches/fnm_multishells/985_1655820447617/bin/npm
  Browsers:
    Chrome: 102.0.5005.115
    Firefox: 101.0.1
    Safari: 16.0
  npmPackages:
    vitepress: ^1.0.0-alpha.2 => 1.0.0-alpha.2

Additional context

Workaround:

{
  outDir: process.env.OUT_DIR && path.resolve(process.env.OUT_DIR),
}

Validations

  • [X] Follow our Code of Conduct
  • [X] Read the docs.
  • [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.

JounQin avatar Jun 22 '22 08:06 JounQin

root: string = process.cwd(),

https://github.com/vuejs/vitepress/blob/baf8083e668ce50a9d26d9398609e196237ebc95/src/node/config.ts#L110-L119

kecrily avatar Jun 22 '22 08:06 kecrily

@kecrily When run vitepress build docs, root is docs

https://github.com/vuejs/vitepress/blob/378f9b4695823dec993239312cda43d71542f570/src/node/cli.ts#L11

JounQin avatar Jun 22 '22 08:06 JounQin

When you specify root in cli, then it is of course the highest priority.

kecrily avatar Jun 22 '22 08:06 kecrily

When you specify root in cli, then it is of course the highest priority.

It is very common to use vitepress build docs, but for outDir, resolve from pwd should be preferred IMO.

JounQin avatar Jun 22 '22 08:06 JounQin

I don't think so. It can cause problems when using vitepress in an existing repository (like a vitepress repository).

It is common for people to write the docs:build script in . /package.json. And if its code needs to be compiled it may be output to dist, which is overwritten if vitepress uses pwd.

Of course this can be solved by customizing outDir, but I think it's just a pain in the ass.

kecrily avatar Jun 22 '22 09:06 kecrily

Of course this can be solved by customizing outDir, but I think it's just a pain in the ass.

The default outDir is always resolve(root, 'dist'), I'm using custom outDir: 'dist/docs' now, which resolves docs/dist/docs unexpectedly.

JounQin avatar Jun 22 '22 09:06 JounQin

It's the expected behavior. https://vitepress.dev/reference/site-config#outdir

brc-dd avatar Mar 10 '23 09:03 brc-dd