繁体   English   中英

在React应用中更改index.html的路径

[英]Change the path of index.html in a react app

我创建了一个React App,默认情况下,index.html转到公用文件夹。 因此,当我运行命令npm start时,index.html必须位于公用文件夹中,否则会出现以下错误:

...
react-scripts start

Could not find a required file.
  Name: index.html
...

所以我的问题是,是否有任何方法可以将index.html更改为根路径。

我的意思是:

从这里开始(这是默认设置)

my-app/
  README.md
  node_modules/
  package.json
  public/
    index.html
    favicon.ico
  src/
    App.css
    App.js
    App.test.js
    index.css
    index.js
    logo.svg

到这里:

my-app/
  README.md
  node_modules/
  package.json
  public/
    favicon.ico
  src/
    App.css
    App.js
    App.test.js
    index.css
    index.js
    logo.svg
index.html

我需要执行此操作,因为我有一个名为record.js的javascript文件,我希望将其包含在index.html中,但是我也希望它可以被称为Speech.js的组件使用,因此我唯一看到的方法是可以做到这一点。

一种简单的方法是创建一个新应用

npm install -g create-react-app
create-react-app App

您将拥有一个如下所示的文件夹结构:

App/
  README.md
  **index.html**
  favicon.ico
  node_modules/
  package.json
  src/
    App.css
    App.js
    index.css
    index.js
    logo.svg

如您所见,index.html在根路径中,因此您只需要向其中添加文件即可。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM