浅析html webpack plugin插件的使用教程
2020-05-10 04:06
1036 查看
使用html-webpack-plugin插件来启动页面 可将html页面放入内存 以提升页面的加载速度
并且还能自动设置index.html页面中JS文件引入的路径
使用前提:项目中安装了Webpack使用步骤:
步骤一、在项目的根目录下输入cnpm i html-webpack-plugin -D
将html-webpack-plugin插件安装到开发依赖
其作用是根据指定的模板页面在内存中生成相应的HTML页面
步骤二、插件安装之后 修改webpack.config.js的配置文件
在配置文件中导入html-webpack-plugin插件 并配置模板页路径和生成的页面名称即可
const path=require("path") // 导入html-webpack-plugin const htmlWebpackPlugin=require("html-webpack-plugin") module.exports={ entry:path.join(__dirname,"./src/main.js"), output:{ path:path.join(__dirname,"./dist"), filename:"bundle.js" }, // 配置插件节点 plugins:[ // 创建html-webpack-plugin插件 new htmlWebpackPlugin({ // 设置参数 template:path.join(__dirname,"./src/index.html"), // 指定模板页面 以根据指定页面生成内存中的页面 filename:"index.html" // 指定生成的内存中的页面的名称 }) ] }
使用了html-webpack-plugin插件之后 就无需手动处理bundle.js的引用路径了
因为 在生成后的内存中的HTML页面里 已经自动引入了bundle.js的正确路径
总结 - 插件的作用:
1、自动根据指定的页面生成一个在内存中的页面
2、自动在页面中引入打包好的bundle.js
到此这篇关于浅析html webpack plugin插件的使用教程的文章就介绍到这了,更多相关html webpack plugin插件内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!
相关文章推荐
- [js高手之路]深入浅出webpack教程系列6-插件使用之html-webpack-plugin配置(下)
- [js高手之路]深入浅出webpack教程系列6-插件使用之html-webpack-plugin配置(下)
- [js高手之路]深入浅出webpack教程系列5-插件使用之html-webpack-plugin配置(中)
- [js高手之路]深入浅出webpack教程系列4-插件使用之html-webpack-plugin配置(上)
- [js高手之路]深入浅出webpack教程系列4-插件使用之html-webpack-plugin配置(上)
- html-webpack-plugin插件使用chunks属性时报错
- html-webpack-plugin插件的详细介绍和使用
- webpack插件:使用HtmlWebpackPlugin在页面中使用EJS语法引用模板文件(二)
- webpack 插件html-webpack-plugin的具体使用
- HtmlWebpackPlugin插件使用实现html文件自动生成
- webpack 浅析-- htmlWebpackPlugin 插件
- 9.1webpack配置文件以及webpack-dev-server 工具html-webpack-plugin插件使用
- webpack的使用(插件HtmlWebpackPlugin)
- 使用html-webpack-plugin'入再内存中生成 html 页面插件
- webpack插件-html-webpack-plugin
- webpack 插件: html-webpack-plugin
- html-webpack-plugin 中使用 title选项设置模版中的值无效
- webpack学习(三)html-webpack-plugin插件
- webpack.optimize.CommonsChunkPlugin插件的使用
- htmlWebpackPlugin的使用