I am using HtmlWebpackPlugin in webpack and below is its configuration:
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: 'body',
sdk: '/mylib.js'
})
In my html I define the script tag as:
<script src="<%= htmlWebpackPlugin.options.sdk %>"></script>
webpack will replace the <%= htmlWebpackPlugin.options.sdk %> with /mylib.js. However it doesn't work once I add the html-loader plugin as below:
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
options: {
attrs: 'img:src'
}
}
]
}
The reason I use html-loader is to parse the img src tag on html file. But it conflicts with HtmlWebpackPlugin <%= ... %> expression. How can I make both of them work?