【问题标题】:I want to move my index.html to the public folder in a vite react project but then I get an error我想将我的 index.html 移动到 vite react 项目中的 public 文件夹,但随后出现错误
【发布时间】:2023-02-24 05:42:54
【问题描述】:

我有这个项目结构:

> Assets
> node_modules
> public
> src
  .gitignore
  .index.html
   package-lock.json
   package.json
   vite.config.js

在我的索引 html 中,我有指向 ./src/main.jsx 的脚本

现在的事情是我想将我的 index.html 文件移动到 public 文件夹中,我将我的脚本从 index.html 文件更改为指向../src/main.jsx,我添加了根键以指向 vite 中的“public” .config.js 文件,但当我运行 npm run dev 时,我得到的只是一个空白页面,浏览器控制台中出现此错误消息:GET http://localhost:5173/src/main.jsx net::ERR_ABORTED 404 (Not Found ).有什么想法吗?

【问题讨论】:

  • 你为什么要这样做?通常它会在 src 中,并且在生产构建中将在 dist 中生成一个 index.html,您将使用它在 prod 中提供服务。

标签: reactjs vite


【解决方案1】:

查看文档。它描述了为什么你不应该这样做。

https://vitejs.dev/guide/#index-html-and-project-root

【讨论】:

    猜你喜欢
    • 2021-07-14
    • 2017-10-26
    • 2021-06-17
    • 2021-09-09
    • 2022-08-03
    • 1970-01-01
    • 2018-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多