7月7日学习打卡

学习目标:webpack一些常用的打包方法和怎么重写vue中的push和replace方法


学习内容:webpack

  1. html-webpack-plugin的使用
  1. 清理dist
//在出口文件加上这个,再次使用npx webpack打包时,原来的html文件就会被替换
clean:true

      1.使用source map精准定位错误的代码

//在开发模式下追踪代码
devtool:'inline-source-map',

      2.资源模块(允许webpack打包其他的资源文件)

         (1)asset/resource(会发送一个单独的文件并导出url)

module:{
        rules:[
            {
                test: /\.jpg$/,
                //加载图片资源
                type:'asset/resource',
                //优先级较高
                generator:{
                    filename:'images/[contenthash][ext]'
                }
            }
]
}

         (2)asset/inline(他会导出一个资源的Data URL)

module:{
        rules:[
            {
                
                test:/\.svg$/,
                type:'asset/inline'
            
            },
]
}

         (3)asset/source(导出资源的原代码)

module:{
        rules:[
            {
                
                test:/\.txt$/,
                type:'asset/source'
            
            },
]
}

         (4)asset/source(在resource和inline之间自动选择)

module:{
        rules:[
            {
                 test:/\.jpg$/,
                type:'asset',
                parser:{
                    dataUrlCondtion:{
                        //当图片大于4m时才会生成一个资源文件
                        maxSize:4*1024*1024
                    }
                }
            
            },
]
}

3.重写router里的push和replace方法

// //先把VueRouter原型对象的push,先保存一份
let oringinPush= VueRouter.prototype.push;
let oringinReplace = VueRouter.prototype.replace;
// //重写push和replace
// //第一个参数:告诉原来的push方法,你往哪里跳转(传递哪些参数)
Vue.prototype.push = function(location,resolve,reject){
    if(resolve && reject){
        oringinPush.call(this,location,resolve,reject);
    }else{
        oringinPush.call(this,location,()=>{},()=>{})
    }
}
//location是往哪里跳
Vue.prototype.replace = function(location,resolve,reject){
    if(resolve && reject){
        oringinReplace.call(this,location,resolve,reject);
    }else{
        oringinReplace.call(this,location,()=>{},()=>{})
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值