inject external tag to html
npm install --save-dev html-webpack-inject-plugin
Require the plugin in your webpack config
import HtmlWebpackInjectPlugin from 'html-webpack-inject-plugin'
// or
const HtmlWebpackInjectPlugin = require('html-webpack-inject-plugin').default
Add the plugin to your webpack config as follows
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html'
}),
new HtmlWebpackPlugin({
filename: 'other.html'
}),
new HtmlWebpackInjectPlugin({
externals: [
{
tagName: 'script',
attributes: {
src: 'common-script.js',
type: 'text/javascript'
}
},
{
tagName: 'script',
attributes: {
src: 'only-inject-to-other-script.js',
type: 'text/javascript'
},
include: ['other.html']
}
],
prepend: true // default is false
})
]
externals: <HtmlAssetItem>[]
: external HTMLTagObject which you want to addprepend
: insert before parent first child