nuxt按需加载vant

  1. 安装插件
npm install babel-plugin-import less less-loader path -D

2.plugins新建vant-ui.js

import Vue from 'vue';
import { Button } from 'vant'
Vue.use(Button);

3.nuxt.config.js配置插件

build:{
    //  按需加载vant
  transpile: [ /vant.*?less/ ],
  babel: {
    plugins: [
      ['import', {
        libraryName: 'vant',
        "style": (name) => {
          return `${name}/style/less.js`
        }
      }, 'vant']
    ],
  },
}

5.assets/less/var.less

@tabs-bottom-bar-color: blue;
@tab-active-text-color: blue;
@tab-text-color:#646566;

6.nuxt.config.js中配置

const path = require("path");
cosnt resolve = (dir) => path.join(__dirname, dir);
module.export{
    build:{
        extend(config){
            //修改vant主题
config.module.rules.push({
  test: /\.less$/,
  use: [{
    loader: "less-loader",
    options: {
      modifyVars: {
        // 直接覆盖变量
        hack: `true; @import "${resolve(
          "./assets/less/var.less"
        )}";`
      }
    }
  }]
});
        }
    }
}

1.文本压缩
npm install compression-webpack-plugin
nuxt.config.js中农
const CompressionPlugin = require('compression-webpack-plugin');
module.exports={
    build: {
        plugins: [
          new CompressionPlugin({
            test: /\.js$|\.html$|\.css/, // 匹配文件名
            threshold: 10240, // 对超过10kb的数据进行压缩
            deleteOriginalAssets: false // 是否删除原文件
          })
        ],
        optimization: {
              splitChunks: {
               minSize: 10000,
                maxSize: 250000
              }
        },
    }
}

nuxt打包后删除console.log()信息

1.安装插件

npm install babel-plugin-transform-remove-console -D

2.nuxt.config.json配置

let consolePlugins = []
if (process.env.NODE_ENV === 'production') {
  consolePlugins.push("transform-remove-console")
}
//build配置
build:{
    babel: {
      consolePlugins
	},
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值