簡體   English   中英

在 React 項目中添加 js 腳本

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM