[英]Adding js script to the React project
如何向 react 項目添加一個簡單、經典的js腳本? 我試圖通過添加來添加它
<script src="../src/alert.js"></script>
在index.html的頭部,但它似乎不起作用!
在底層,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
中導入它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.