Webpack.config how to just copy the index.html to the dist folder

后端 未结 9 1698
醉梦人生
醉梦人生 2020-12-07 08:14

I am trying to automate assets going into /dist. I have the following config.js:

module.exports = {
  context: __dirname + "/lib",
  entry: {
    m         


        
9条回答
  •  南方客
    南方客 (楼主)
    2020-12-07 09:20

    To copy an already existing index.html file into the dist directory you can simply use the HtmlWebpackPlugin by specifying the source index.html as a template.

    const HtmlWebpackPlugin = require('html-webpack-plugin');
    
    module.exports = {
      // ...
      plugins: [    
        new HtmlWebpackPlugin({
          template: './path/to/index.html',
        })
      ],
      // ...
    };
    

    The created dist/index.html file will be basically the same as your source file with the difference that bundled resources like .js files are injected with

提交回复
热议问题