当前位置:Gxlcms > JavaScript > webpack-plugin插件实例介绍

webpack-plugin插件实例介绍

时间:2021-07-01 10:21:17 帮助过:8人阅读

1,项目安装 html-webpack-plugin 插件
npm install html-webpack-plugin --save-dev

2,引用 html-webpack-plugin 插件
var htmlWebpackPlugin = require('html-webpack-plugin');

3,调用 html-webpack-plugin 插件
module.exports = {
    plugins: [new htmlWebpackPlugin({
            title: "this is title", //用于生成的HTML文档的标题。filename: "index.html", // 生成的模板文件的名字 默认index.htmltemplate: "index.html", //模板来源文件inject: false, //注入位置'head','body',true,falsefavicon: "", //指定页面图标            minify: {
                caseSensitive: false, ////是否大小写敏感collapseBooleanAttributes: true, //是否简写boolean格式的属性如:disabled="disabled" 简写为disabled collapseWhitespace: true //是否去除空格            },
            hash: true, //是否生成hash添加在引入文件地址的末尾,类似于我们常用的时间戳,这个可以避免缓存带来的麻烦cache: true, //是否需要缓存,如果填写true,则文件只有在改变时才会重新生成showErrors: true, //是否将错误信息写在页面里,默认true,出现错误信息则会包裹在一个pre标签内添加到页面上chunks: ['a', 'b'], //引入的a,b模块,这里指定的是entry中设置多个js时,在这里指定引入的js,如果不设置则默认全部引入,数组形式传入chunksSortMode: "auto", //引入模块的排序方式excludeChunks: ['a', 'b'], //排除的模块,引入的除a,b模块以外的模块,与chunks相反xhtml: false //生成的模板文档中标签是否自动关闭,针对xhtml的语法,会要求标签都关闭,默认false        })
    ]
};



以上就是webpack-plugin插件实例介绍的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行