简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM