Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change root path, entry html's source require will not found #4759

Open
7 tasks done
huchangfa123 opened this issue Aug 27, 2021 · 7 comments
Open
7 tasks done

change root path, entry html's source require will not found #4759

huchangfa123 opened this issue Aug 27, 2021 · 7 comments
Labels
feat: html p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@huchangfa123
Copy link

huchangfa123 commented Aug 27, 2021

Describe the bug

After changing root path, in vite.config .
image
source which required in entry html , will not found.

image
image

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

@bluwy
Copy link
Member

bluwy commented Mar 18, 2022

I can reproduce this with the react template and moving the index.html to a folder. It's very similar to #4760. Likely the same core issue with Vite now allowing or incorrectly resolving files outside of the root.

@waynebloss
Copy link

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"),
    },
  },
});

Copy link

stackblitz bot commented Nov 7, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@zhang592135258
Copy link

I have looked at the related problems you mentioned in the past, but I have not found relevant solutions in them

@Rey-Wang
Copy link

@waynebloss what's your folder structure

@waynebloss
Copy link

@Rey-Wang

  • dist/
  • public/
  • src/
    • index.html

And the vite config is on the root level with dist, public, src…

@aleclarson
Copy link
Member

#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: html p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

8 participants