您的位置:首页 >> Vue >> 《和小米一起学Vue.js》— webpack插件

《和小米一起学Vue.js》— webpack插件

[ 孤狼 | 2022-07-30 03:09:16 | Vue | 1136°C | 0条评论 ]

在webpack中,可以使用一些插件来实现一些高级的功能。比如自动加注释,自动复制文件等等。这里我们装一个自动应用html文件到dist目录的插件。


html-webpack-plugin

html-webpack-plugin插件可以按指定的模板生成index.html文件,同时自动添加引用。


安装html-webpack-plugin

npm install html-webpack-plugin --save-dev


修改webpack.config.js文件

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


修改index.html

修改index.html 删除之前引用的js文件

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>webpack</title>
</head>
<body>
<div id="app"></div>
</body>
</html>


打包运行

输入命令打包

npx webpack

之后根目录下的index.html文件就不用再修改了    



代码下载

下载地址:  密码:hrgj




转载请注明出处:http://gl.paea.cn/n.php?n=187
 
如您看得高兴,欢迎随意投喂,让我们坚持创作!
赞赏一个鸡腿
还没有人留下遗迹
综合 · 搜索