Webpack: How to inject javascript into the HTML instead of separate JS file

安稳与你 提交于 2020-06-27 09:02:23

问题


Is there a way to have webpack inject the output into the HTML instead of a separate file?

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

回答1:


I had to use the html-webpack-inline-source-plugin. https://github.com/DustinJackson/html-webpack-inline-source-plugin

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


来源:https://stackoverflow.com/questions/52846031/webpack-how-to-inject-javascript-into-the-html-instead-of-separate-js-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!