Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 427
Stephen Gilboy Avatar asked Oct 17 '22 11:10

Stephen Gilboy


1 Answers

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()
] 
like image 136
Stephen Gilboy Avatar answered Oct 21 '22 05:10

Stephen Gilboy