bundle.js 在生成的 webpack 中包含两次 index.html

bundle.js included twice in webpack generated index.html

我的 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 将包注入 html 开箱即用