Webpack:如何将JavaScript注入HTML而不是单独的JS文件

时间:2018-10-17 01:20:14

标签: javascript webpack webpack-4

有没有办法让webpack将输出注入HTML而不是单独的文件中?

<html>
  <head>
  </head>
  <body>
    <script type="text/javascript">
      // webpack puts the output here
    </script>
  </body>
</html>

1 个答案:

答案 0 :(得分:1)

我不得不使用html-webpack-inline-source-pluginhttps://github.com/DustinJackson/html-webpack-inline-source-plugin

plugins: [
  new HtmlWebpackPlugin({
    inlineSource: '.(js|css)$' // embed all javascript and css inline
  }),
  new HtmlWebpackInlineSourcePlugin()
]