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

时间:2018-08-01 06:11:18

标签: reactjs webpack webpack-4

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

文件夹结构

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

用户界面-> 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在构建文件夹下生成了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都会包含两次

1 个答案:

答案 0 :(得分:1)

从index.html中删除对bunde.js的手动引用。 HtmlWebpackPlugin开箱即用地将捆绑软件注入html