【问题标题】:bundle.js included twice in webpack generated index.htmlbundle.js 在 webpack 生成的 index.html 中包含两次
【发布时间】:2019-01-08 14:53:26
【问题描述】:

我的 webpack 4 在 build 文件夹中生成 index.html,并且 bundle.js 在生成的 index.html 中包含两次。

文件夹结构

ui > 
   webpack.config.js
   index.html
   build >
         index.html
         bundle.js

ui --> index.html

<html>

<head>
    <link href="https://fonts.googleapis.com/css?family=Cabin+Sketch" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>

<body>
    <div id="App">
        <!-- this is where the root react component will get rendered -->
    </div>
    <script type="text/javascript" src="/bundle.js"></script></body>

</html>

webpack在build文件夹下生成index.html

<html>

<head>
    <link href="https://fonts.googleapis.com/css?family=Cabin+Sketch" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>

<body>
    <div id="App">
        <!-- this is where the root react component will get rendered -->
    </div>
    <script src=build/rapido-web.js></script>
<script type="text/javascript" src="/rapido-web.js"></script>
   </body>

</html>

知道为什么 bundle.js 包含两次

【问题讨论】:

  • 从 index.html 中删除对 bunde.js 的手动引用。 HtmlWebpackPlugin 将 bundle 注入到 thml 中

标签: reactjs webpack webpack-4


【解决方案1】:

从您的 index.html 中删除对 bunde.js 的手动引用。 HtmlWebpackPlugin 将 bundle 注入开箱即用的 html

【讨论】:

  • 感谢您的回答。如果您认为我的问题有效,请投票。
猜你喜欢
  • 2018-05-19
  • 1970-01-01
  • 2017-02-25
  • 2018-03-17
  • 2021-09-20
  • 1970-01-01
  • 2020-02-13
  • 1970-01-01
  • 2018-10-10
相关资源
最近更新 更多