vite
vite copied to clipboard
change root path, entry html's source require will not found
Describe the bug
After changing root path, in vite.config .
source which required in entry html , will not found.
Reproduction
https://stackblitz.com/edit/vitejs-vite-1dynea?file=ss%2Findex.html,vite.config.js&terminal=dev
System Info
System:
OS: macOS 10.15.7
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 149.41 MB / 32.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 14.17.0
Yarn: 1.22.10
npm: 6.14.13
Browsers:
Chrome: 92.0.4515.159
Safari: 14.1.2
npmPackages:
vite: ^2.5.0 => 2.5.0
Used Package Manager
yarn
Logs
No response
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
I can reproduce this with the react template and moving the index.html
to a folder. It's very similar to https://github.com/vitejs/vite/issues/4760. Likely the same core issue with Vite now allowing or incorrectly resolving files outside of the root.
Here's how I got it working the way I wanted it:
export default defineConfig({
envDir: __dirname,
publicDir: Path.join(__dirname, "public"),
root: Path.join(__dirname, "src"),
build: {
outDir: Path.join(__dirname, "dist"),
rollupOptions: {
input: [Path.join(__dirname, "src/index.html")],
},
},
plugins: [
viteReact(),
],
resolve: {
alias: {
"@": Path.resolve(__dirname, "./src"),
},
},
});
I have looked at the related problems you mentioned in the past, but I have not found relevant solutions in them
@waynebloss what's your folder structure
@Rey-Wang
- dist/
- public/
- src/
- index.html
And the vite config is on the root level with dist, public, src…
#16629 should make this easier. The idea is you'd keep root
set to the actual root directory and set entryRoot
to "src" or wherever your index.html
is kept.