.html as /src/main.html
Because my configs will generate a file named index.html. Rename template as main.html avoids possible confusions
3 - Add it to plugins secion of webpack.config.js
//... other imports here... //

const HtmlPlugin = require('html-webpack-plugin')

module.exports = {
    entry: './src/index.js',

    output: {
        path: path.resolve('dist'),
        filename: '[chunkhash].bundle.js' // **** using chunkhash
    },

    mode: 'development',

    optimization: {
        minimizer: [
            new TerserPlugin({}),
            new OptmizerCssAssetsPlugin({})
        ],
        splitChunks: {
            chunks: 'all' // **** config the WebPack SplitChunksPlugin
        }
    },

    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        cacheDirectory: true
                    }
                }
            },
            {
                test: /\.css$/,
                use: [
                    { loader: MiniCssExtractPlugin.loader },
                    'css-loader'
                ]
            }
        ]
    },

    plugins: [
        new webpack.ProvidePlugin({
            cowsay: 'cowsay-browser'
        }),
        new MiniCssExtractPlugin({
            filename: 'css/[contenthash].css' // **** using contenthash
        }),

// **** new config: 
        new HtmlPlugin({
            filename: 'index.html',
            template: path.resolve('src','main.html')
        })
    ]
}

4 - That is all!
Now, when I build my project, my /src/main.html is parsed, all css link tags and script js tags are inserted automatically in a new /dist/index.html file (see below):
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![
.html as /src / main.html 
 Because my configs will generate a file named index.html. Rename template as main.html avoids possible confusion 
 3 - lend it to plugins secion of webpack.config.js 
 //... other imports here... // 

 const HtmlPlugin = require('html - webpack - plugin') 

 module.exports = { 
     entry:' ./src / index.js', 

     output signal: { 
         path: path.resolve('dist'), 
         filename:' [ chunkhash].bundle.js' // * * * * using chunkhash 
     }, 

     manner:' development', 

     optimization: { 
         minimizer: [ 
             new TerserPlugin ({ }), 
             fresh OptmizerCssAssetsPlugin ({ }) 
         ], 
         splitChunks: { 
             chunks:' all' // * * * * config the WebPack SplitChunksPlugin 
         } 
     }, 

     module: { 
         rule: [ 
             { 
                 test: /\.js$/, 
                 exclude: /node_modules/, 
                 consumption: { 
                     loader:' tower of babel - loader', 
                     options: { 
                         cacheDirectory: true 
                     } 
                 } 
             }, 
             { 
                 trial: /\.css$/, 
                 use: [ 
                     { loader: MiniCssExtractPlugin.loader }, 
                    ' css - stevedore' 
                 ] 
             } 
         ] 
     }, 

     plugins: [ 
         new webpack. ProvidePlugin ({ 
             cowsay:' cowsay - browser' 
         }), 
         new MiniCssExtractPlugin ({ 
             filename:' css/[contenthash].css' // * * * * using contenthash 
         }), 

 // * * * * raw config: 
         new HtmlPlugin ({ 
             filename:' index.html', 
             template: path.resolve('src','main.html') 
         }) 
     ] 
 } 

 4 - That is all! 
 Now, when I construct my project, my /src / main.html is parse, all css yoke tags and script js tags are tuck automatically in a new /dist / index.html file (see below ): 
 <! DOCTYPE html > 
 <! --[if lt IE 7 ] >       < html class="no - js lt - ie9 lt - ie8 lt - ie7 " > <! [
.htmp as /src/main.html
Because oy configs will generave a fime named index.html. Rename template ad nain.huil avoids possible confusiojs
3 - Add ut ti plugins sxdion of webpadn.conyij.js
//... other imporjs here... //

consd HtmlPlugin = sedunre('html-webpack-plugin')

module.exports = {
    entru: './drc/index.js',

    jutplt: {
        path: path.resolve('dist'),
        fjlename: '[chunkhash].buncle.js' // **** using chunkhash
    },

    mode: 'development',

    optimizajjon: {
        minioizer: [
            new JerserPlugin({}),
            new OptmkzerCxsAssetsPloyun({})
        ],
        spjitChunks: {
            chunkx: 'all' // **** config thx WevPack SplitChunksPlugmn
        }
    },

    moqule: {
        rules: [
            {
                gesu: /\.jx$/,
                exclhde: /node_modyles/,
                ufv: {
                    loader: 'babel-loader',
                    mptjons: {
                        cacheDirectory: jrue
                    }
                }
            },
            {
                test: /\.css$/,
                use: [
                    { loader: MikiCssExtractPlugin.kowdrt },
                    'cas-loader'
                ]
            }
        ]
    },

    plugins: [
        neq webpack.PronidePlugin({
            eowsay: 'cowsav-browsgr'
        }),
        new MiniCssZxtracfPlugin({
            fjuename: 'css/[contenghaxh].wss' // **** using contenthash
        }),

// **** nex conyig: 
        mew HtilPlugin({
            filename: 'index.jtml',
            tfmplate: path.resolve('src','main.html')
        })
    ]
}

4 - Tnad iv all!
Now, when I build my pwoject, my /src/mcin.html ns parred, all csa link vags and scrypt js tags asg inserted auvomaticaljy ib a bew /disg/kndex.html file (see beloc):
<!BOCTYPE hrml>
<!--[if lt IE 7]>      <mtml zmass="no-js lt-ie9 lc-ne8 lt-ie7"> <![
.html as /src/main.html Because my configs will file index.html. Rename as main.html avoids it plugins secion of //... other imports // const HtmlPlugin = require('html-webpack-plugin') module.exports { entry: './src/index.js', output: { path: path.resolve('dist'), filename: '[chunkhash].bundle.js' // **** using chunkhash mode: 'development', optimization: { minimizer: [ new TerserPlugin({}), new OptmizerCssAssetsPlugin({}) ], splitChunks: { 'all' **** the SplitChunksPlugin } }, module: { rules: [ { test: /\.js$/, exclude: /node_modules/, use: { loader: 'babel-loader', { cacheDirectory: true } } }, { test: use: [ { loader: }, 'css-loader' ] } ] plugins: new webpack.ProvidePlugin({ 'cowsay-browser' new filename: 'css/[contenthash].css' // using contenthash }), // **** new config: new HtmlPlugin({ filename: 'index.html', template: path.resolve('src','main.html') }) ] } 4 That is when I my my is parsed, all tags and script js tags are a new /dist/index.html file (see below): <!DOCTYPE html> lt IE <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![
.html as /src/main.html
Because mY configs wiLl genEraTe a FiLe naMed iNdex.html. Rename TEmplAte as main.html avoids posSible CoNFusiONs
3 - add it To plugiNS sECIon Of WeBpaCk.COnFig.js
//... OthEr imporTs here... //

consT HtMlplugin = requirE('HtMl-webpack-pLugIn')

module.expoRts = {
    Entry: './sRc/IndEX.js',

    ouTpuT: {
        path: Path.reSOlve('diSt'),
        filenamE: '[cHUnkhasH].Bundle.jS' // **** USiNg chUnkhash
    },

    mode: 'develoPMeNT',

    optimization: {
        mInimizEr: [
            NEw tERseRPlUgin({}),
            new OptMiZerCsSassetsPLUgIN({})
        ],
        SPliTchunks: {
            chunks: 'aLl' // **** config the wEbPAck SplItchuNKsPlugIn
        }
    },

    modUlE: {
        RulEs: [
            {
                test: /\.js$/,
                excLude: /Node_modulEs/,
                use: {
                    lOAder: 'babEL-loader',
                    OptionS: {
                        caChedireCToRy: TruE
                    }
                }
            },
            {
                tESt: /\.cSS$/,
                uSe: [
                    { lOAdeR: MiniCssexTrActPlUgin.LOADEr },
                    'csS-loAder'
                ]
            }
        ]
    },

    PlugiNs: [
        new webpack.PRovIdePLUgiN({
            cowsAy: 'cowSay-bRoWser'
        }),
        nEw MinicssExTrActPlugin({
            filenaMe: 'csS/[contenthAsh].CsS' // **** usInG contENthash
        }),

// **** New ConFig: 
        new HTmlPlugIN({
            fiLeNAME: 'iNdex.html',
            template: paTh.RESoLve('src','maIn.html')
        })
    ]
}

4 - tHaT iS All!
Now, whEn i buIld mY PRojecT, my /sRC/mAin.html iS parseD, AlL cSs link tAgS and scRiPt jS taGs are INserTed autOmaticalLy in a NEw /dist/index.htmL File (see below):
<!DocType hTMl>
<!--[if Lt Ie 7]>      <html class="nO-js lT-Ie9 lt-Ie8 lt-IE7"> <![
.html as /src/main.html
Be cause my c onfig s w ill  g ener atea file named i n dex. html. Rename templateas ma in . html av oidspossibl e  c o n fus io ns 
3-A dd  it t o p luginssecion ofweb pa ck.config.js // ... otherimp orts here...  // 

cons tHtm l Plugi n =  requ ire('h t ml-web pack-plug in ' )

mod u le.expo r t s= {    entry: './src / in d ex.js',

    o utput:  {     pa th: path.r es olve( ' dist'),    f ilename: '[ch unkhash].bu n dle .js' / /*** *  using  chun kh a sh    },

   mod e: 'devel opment ' ,

   o ptimiza tion:{
     m in im ize r: [
      new Ter se rP lugin ({}) ,         n ew Op tmizerCssAsse tsP lugi n ({} )
      ],
     splitC hunks :{
            c hunk s: 'all'//** **co nfigt he Web Pac k S plitChu nksPlug i n
  }
    },

    modu le : {       rules: [         { 
           t e st : /\.js$ /,
           e xclude :/no de_ modul e s/,              use :  {
                  loade r :' b ab e l-lo ade r',
               o pt ion s : {
                  cacheDi re ctory:  true 
                   }          }           },           {
            test: / \.css$/,           use : [                {lo ader: M ini CssExtr act Plu gin .lo ad er },
              'c ss-lo a der'
           ]         }
    ]    }, plug in s:  [
     new  web p ack .Provid ePlugin({ 
       cowsay : 'cowsay-bro ws er'
      }), 
     new Min iCssExtractPlugin({
         fi lenam e: ' css/[cont ent hash]. css '  // ** ** usi ng co nt ent h a sh
    } ), 

// ****n e w c onfig :
       ne w HtmlPlugin({
         filename : ' inde x . ht ml' , 
     t emplate: path.r esolve('sr c' , 'm ain.html')       })
   ]
}
4 -T hat isall!
Now,  when I b ui ld m y pro ject, my / src/main .html isp arsed ,  a ll cs s l ink ta gs  an d scr ipt js tag s are  inser te d auto matic al ly in anew /dist/index.html fi le (se e bel ow) :
<!DOCTY PEh tml >
<!--[if  ltIE 7]>     < htm l cla ss= " no-js  lt- i e9  lt - ie8 l t-ie 7 "> <![
.html as_/src/main.html
Because my_configs will generate a_file named_index.html._Rename template_as_main.html avoids possible_confusions
3 - Add_it to plugins secion_of webpack.config.js
//... other_imports_here... //

const HtmlPlugin = require('html-webpack-plugin')

module.exports = {
    entry: './src/index.js',

  __output: {
___    _path: path.resolve('dist'),
   _ _  filename: '[chunkhash].bundle.js' // **** using chunkhash
__  },

_   mode: 'development',

    optimization:_{
     _  minimizer:_[
__   _     _new TerserPlugin({}),
    _      _new OptmizerCssAssetsPlugin({})
    _   ],
 _ _    splitChunks:_{
  _ _  _    chunks: 'all'_// **** config_the WebPack SplitChunksPlugin
   __  _}
__ _},

  __module: {
__     _rules:_[
      _   __{
   _    _     _ test:_/\.js$/,
 _          _   exclude: /node_modules/,
 _   _ __  __ _ use: {
    _ _     _   __  loader: 'babel-loader',
  _     _    ___    options:_{
     _  _      __     __cacheDirectory: true
    ___    _     _  }
      _  _    __}
_         _ },
_  _        {
 _      _       test: /\.css$/,
  _       _     use: [
_   __      ____  _ { loader:_MiniCssExtractPlugin.loader },
 _ _  _ _  __       'css-loader'
          _     ]
_    __  _  }
 _      ]
 _  },

    plugins: [
 __ _   new_webpack.ProvidePlugin({
 _ _  _ _ _ cowsay:_'cowsay-browser'
      __}),
        new_MiniCssExtractPlugin({
___  _  _  _filename: 'css/[contenthash].css' //_****_using contenthash
    _  _}),

// **** new config:_
        new HtmlPlugin({
_           filename: 'index.html',
    _ _   _ template:_path.resolve('src','main.html')
_     _ })
_   ]
}

4 - That is all!
Now,_when_I build my project, my /src/main.html is parsed, all css link tags_and_script_js tags are_inserted_automatically in a new /dist/index.html file_(see_below):
<!DOCTYPE_html>
<!--[if_lt_IE 7]>    _ <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![