如何将简单的经典 js 脚本添加到react项目? 我试图通过添加
来添加它<script src="../src/alert.js"></script>
index.html 的 head 中的,但似乎不起作用!
答案 0 :(得分:1)
Here the Dan Abramov's answer say
在后台,Create React App将Webpack与 html-webpack-plugin。
index.html
用作模板,而index.js
是您应用的入口点
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
因此,如果要加载其他脚本,则必须将其导入index.js
中。