I am trying to inject css file into my index.html. Currently my web pack does the following
- Converts my SASS into CSS
- Name the css file with hash (e.g. optionA-32d6cb.css)
- Places into ./dist folder
output of the folder structure:
- Dist
- OptionA
- optionA-hash.css
- OptionB
- optionB-hash.css
- index.html //How to inject above css into this file?
I am new to HtmlWebpackPlugin my question is how do i inject above dynamic css files into the index.html? so that in the head section i have the following:
<link href="optionA-32d6cb.css" rel="stylesheet">
<link href="optionB-w2d6cb.css" rel="stylesheet">
My webpack.config.js file:
module.exports ={
entry: ['path_to_scss_file'],// SASSfile which contains import statment with wildcard to get all sass in given directory
output: {
filename: "[name].min.js",
path: path.resolve(__dirname, 'dist/'),
},
plugins:[
new HtmlWebpackPlugin({
template: './src/index.html'
})
],
module:{
rules: [
{
test: /\.scss$/,
use: [
{
loader: 'file-loader',
options:{
name:'[name]/[name]-[contenthash].css',
}
},
{
loader: 'sass-loader',
options: {
sassOptions: {
importer: globImporter(),
//my sass files uses wildcard to import all sass files
},
},
}
]
}
]
}