vite icon indicating copy to clipboard operation
vite copied to clipboard

feat(config): add `entryRoot` option

Open aleclarson opened this issue 1 year ago • 1 comments

Description

The entryRoot option allows customization of Vite's dev server and its Rollup build.

  • For the dev server, it determines the root directory used by the htmlFallbackMiddleware and indexHtmlMiddleware handlers. This means I can place my index.html file in the src directory and Vite will resolve / requests to it as long as I set entryRoot: "src" in my Vite config. In the same scenario, any other .html files in my src directory will be resolved as expected.

    • For example, when /foo is requested, the dev server will look for the src/foo.html file. When /foo/ is requested, it looks for src/foo/index.html file. Previously, the dev server would look in the project root, so I would need a ./foo directory instead of a ./src/foo directory (not ideal).
  • For the Rollup build, entryRoot determines the root directory from which the default index.html entry is resolved. The lib.entry and ssr options are also resolved this way.

Note that if the entryRoot is not absolute, it's resolved like so:

path.resolve(config.root, entryRoot)

Opening this PR as a draft since I haven't written tests or updated the docs. Also I'd like some feedback before doing those things.

Fixes #306

aleclarson avatar May 07 '24 21:05 aleclarson

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.