admin管理员组文章数量:1278914
I am using create-react-app
mand to create an empty app, I got these file in src
folder:
App.css
App.js
App.test.js
index.css
index.js
logo.svg
serviceWorker.js
setupTests.js
After I make a build via npm run build
, index.html
is generated in build
folder.
I created one manually in src
folder, but the build doesn't take it.
The index.js
content is:
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
There is no root
element at all.
I need to add in some <script>
tag inside index.html
to include some third party scripts (which cannot be installed by nodejs), where can I add them since it is not existed in src
folder?
I am using create-react-app
mand to create an empty app, I got these file in src
folder:
App.css
App.js
App.test.js
index.css
index.js
logo.svg
serviceWorker.js
setupTests.js
After I make a build via npm run build
, index.html
is generated in build
folder.
I created one manually in src
folder, but the build doesn't take it.
The index.js
content is:
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
There is no root
element at all.
I need to add in some <script>
tag inside index.html
to include some third party scripts (which cannot be installed by nodejs), where can I add them since it is not existed in src
folder?
-
2
It's usually under
public
folder – MorKadosh Commented Sep 3, 2020 at 6:20 - @MorKadosh you are right! really out of expectation... – Sam YC Commented Sep 3, 2020 at 6:23
2 Answers
Reset to default 10You have to check public folder in the root directory only. You will get your index.html would be there. and your index.js file which is in src folder is the single point of connection between them(main index.html in public folder and all Javascript code which is in src folder).
You should download that third party lybrairie and put it inside of the public directory and include a script
tag inside of the index.html
file which is inside of the public
directory of your project.
The configuration of the create-react-app
is using webpack which is preconfigure to load the public\index.html
file as the template in which the piled bundle will be injected.
If you want to use the index.html
file which you have create inside of the src
folder you should run npm run eject
which will put all create-react-app configuration at your disposal in your project directory and you could perform changes to webpack figuration file to load src/index.html
file as the template in which the piled bundle will be injected.
本文标签: javascriptreactjs createreactapp missing indexhtml in src folderStack Overflow
版权声明:本文标题:javascript - reactjs create-react-app missing index.html in src folder - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741213080a2359515.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论