webpack---使用插件,常见webpack的plugin,构建vue,react单页面/多页面工程APP必备插件

来源:互联网 发布:被淘宝内部优惠券骗了 编辑:程序博客网 时间:2024/05/20 02:56
  • html-webpack-plugin
const htmlWebpackPlugin=require('html-webpack-plugin');plugins:[        new htmnlWebpackPlugin({            template:'index.html',            filename:'home.html',            title:'webpack',            data:'aaaaaa'        })    ]//向index.html传入title和data变量值,并且生成home.html;一个plugins数组中科院有多个HtmlWebpackPlugin对象实例

  • open-browser-webpack-plugin
const OpenBrowserWebpackPlugin=require('open-browser-webpack-plugin');plugins:[    new OpenBrowserWebpackPlugin({url:'http://localhost:8877'})]//启动webpack之后,自动打开浏览器

  • extract-text-webpack-plugin
const ExtractTextPlugin=require('extract-text-webpack-plugin'); plugins:[     new ExtractTextPlugin('main.css')    ]//插件打包css代码到main.css中

  • copy-webpack-plugin
const CopyWebpackPlugin=require('copy-webpack-plugin');new CopyWebpackPlugin([{    from: __dirname + '/src/public'}]);//作用:把public 里面的内容全部拷贝到编译目录

  • webpack-md5-hash
const WebpackMd5Hash=require('webpack-md5-hash');output: {        //...         chunkFilename: "[name].[chunkhash:6].js"},plugins:[    new WebpackMd5Plugin();]/// 它的作用是生成具有独立hash值的css和js文件,即css和js文件hash值解耦。webpack-md5-hash插件对chunk-hash钩子进行捕获并重新计算chunkhash,它的计算方法是只计算模块本身的当前内容(包括同步模块)。

  • clean-webpack-plugin
const cleanWebpackPlugin=require('clean-webpack-plugin');plugins:[    new cleanWebpackPlugin(['./dist','./build']);]/// build之前清除上次构建生成工程目录dist,build,根据需求传参,可以为数组或字符串

  • clean-webpack-plugin
const progressbarWebpack = require('progress-bar-webpack-plugin');plugins:[    new progressbarWebpack ();]/// 打包过程,以百分比显示打包进度

阅读全文
0 0
原创粉丝点击