- Notifications
You must be signed in to change notification settings - Fork10
architgarg/html-webpack-injector
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Plugin that simplifies injection of chunks intohead andbody usingHtmlWebpackPlugin (with ability to provide async/defer)
npm i --save-dev html-webpack-injector
yarn add --dev html-webpack-injector
This is awebpack plugin that simplifies injection of chunks inhead
andbody
tags of HTML files usingHtmlWebpackPlugin
to serve yourwebpack
bundles. This is especially useful when you want to inject some chunks to head and some chunks to body using HtmlWebpackPlugin.
webpack.config.js
constHtmlWebpackPlugin=require('html-webpack-plugin');constHtmlWebpackInjector=require('html-webpack-injector');module.exports={entry:{index:"./index.ts",index_head:"./index.css"// add "_head" at the end to inject in head.},output:{path:"./dist",filename:"[name].bundle.js"},plugins:[newHtmlWebpackPlugin({template:"./index.html",filename:"./dist/index.html",chunks:["index","index_head"]}),newHtmlWebpackInjector()// Initialize plugin]}
This will generate a filedist/index.html
containing the following
<!DOCTYPE html><html><head><metacharset="utf-8"><title>Archit's App</title><scripttype="text/javascript"src="index_head.bundle.js"></script></head></head><body><scriptsrc="index_bundle.js"></script></body></html>
You have to add_head
in the entry point chunk name and it will be automatically injected in the head.
plugins:[newHtmlWebpackPlugin({template:"./index.html",filename:"./dist/index.html",chunks:["index","index_head"],chunksConfig:{// Added optionasync:["index_head"],defer:["index"]}}),newHtmlWebpackInjector()]
About
Plugin that simplifies injection of chunks into head and body using HtmlWebpackPlugin (with ability to provide async/defer)
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.