webpack4打包报错Entrypoint undefined=index.html的解决办法

目录
文章目录隐藏
  1. HtmlWebpackPlugin
  2. 解决方法
  3. 拓展

本文的内容正如标题,我用的是 webpack4 版本,在打包时可以打包正常,但是总是会打印这句话 Entrypoint undefined=index.html,看着特别难受;度娘了一下说什么的都有,有的说是版本问题,这个我也没有下去印证,所以靠大家。这不是可怕的,可怕的是有问题出现,却没有解决的方法,特此将我的解决方案附上。
webpack4 打包报错 Entrypoint undefined=index.html 的解决办法
这个原因是由 webpack 插件 html-webpack-plugin 引起的

HtmlWebpackPlugin

这个 plugin 曝光率很高,他主要有两个作用

1. 为 html 文件中引入的外部资源如 script、link 动态添加每次 compile 后的 hash,防止引用缓存的外部文件问题。

2. 可以生成创建 html 入口文件,比如单页面可以生成一个 html 文件入口,配置 N 个 html-webpack-plugin 可以生成 N 个页面入口。

github上有些关于 htmlwebpackplugin 的属性介绍,大家可以上去看看。

解决方法

module.exports 增加配置 stats: { children: false }即可解决;

拓展

下面罗列了一些 html-webpack-plugin 插件常用的配置:

plugins:[
        new HtmlWebpackPlugin({
//部分省略,具体看 minify 的配置
minify: {
     //是否对大小写敏感,默认 false
    caseSensitive: true,
    
    //是否简写 boolean 格式的属性如:disabled="disabled" 简写为 disabled  默认 false
    collapseBooleanAttributes: true,
    
    //是否去除空格,默认 false
    collapseWhitespace: true,
    
    //是否压缩 html 里的 css(使用 clean-css 进行的压缩) 默认值 false;
    minifyCSS: true,
    
    //是否压缩 html 里的 js(使用 uglify-js 进行的压缩)
    minifyJS: true,
    
    //Prevents the escaping of the values of attributes
    preventAttributesEscaping: true,
    
    //是否移除属性的引号 默认 false
    removeAttributeQuotes: true,
    
    //是否移除注释 默认 false
    removeComments: true,
    
    //从脚本和样式删除的注释 默认 false
    removeCommentsFromCDATA: true,
    
    //是否删除空属性,默认 false
    removeEmptyAttributes: true,
    
    //  若开启此项,生成的 html 中没有 body 和 head,html 也未闭合
    removeOptionalTags: false, 
    
    //删除多余的属性
    removeRedundantAttributes: true, 
    
    //删除 script 的类型属性,在 h5 下面 script 的 type 默认值:text/javascript 默认值 false
    removeScriptTypeAttributes: true,
    
    //删除 style 的类型属性, type="text/css" 同上
    removeStyleLinkTypeAttributes: true,
    
    //使用短的文档类型,默认 false
    useShortDoctype: true,
    }
    }),
]

「点点赞赏,手留余香」

8

给作者打赏,鼓励TA抓紧创作!

微信微信 支付宝支付宝

还没有人赞赏,快来当第一个赞赏的人吧!

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
码云笔记 » webpack4打包报错Entrypoint undefined=index.html的解决办法

2 评论

  1. webpack4打包报错Entrypoint undefined=index.html的解决办法-码云笔记

  2. 文章不错支持一下吧

回复 头条 取消回复