Aniket Gargya
Aniket Gargya

Reputation: 978

Can I directly inject Javascript into an HTML file with Webpack?

I need to create a standalone HTML file (so no <script src="main.js"></script> tags.

I am using some node_modules and in development, writing it in separate files, but I want to be able to create a webpack.config.js that allows me to directly put the javascript into .html file. I know of HTMLWepackPlugin, but that only create a script tag that includes a source, not actually put the HTML in the file (even with inject: true).

Is there a workaround or another Wepack plugin?

Upvotes: 2

Views: 2243

Answers (1)

Jovan Novakovic
Jovan Novakovic

Reputation: 304

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

Use html-webpack-inline-source-plugin, it is an extension plugin for the html-webpack-plugin functionality by adding the {inlineSource: 'regex string'} option.

Git plugin link

Upvotes: 1

Related Questions