vue-cli4脚手架配置

1 篇文章 0 订阅
1 篇文章 0 订阅
在项目根目录创建vue.config.js文件
const path = require("path"); //引入path模块
function resolve(dir) {
  return path.join(__dirname, dir); //path.join(__dirname)设置绝对路径
}
module.exports = {
  publicPath: "./",
  outputDir: "dist",
  assetsDir: "assets",
  // 反向代理
  devServer: {
    proxy: {
      "/api": {
        target: "http://test.com/",
        changeOrigin: true,
        pathRewrite: {
          "^/api": "/api", // 这种接口配置出来 http://test.com/api/login
          //'^/api': '' 这种接口配置出来 http://test.com/login
          //'^/api': '/' 这种接口配置出来 http://test/login
        },
      },
    },
  },
  // 修改index.html的title标题
  // chainWebpack: (config) => {
  //   // 利用webpack定义title:<%= htmlWebpackPlugin.options.title %>
  //   config.plugin("html").tap((args) => {
  //     args[0].title = "测试标题";
  //     return args;
  //   });
  // },
  /* 是否在构建生产包时生成 sourceMap 文件,false将提高构建速度 */
  productionSourceMap: false,
  lintOnSave: false,
  css: {
    sourceMap: true,
  },
  // 引入全局less------start
  chainWebpack: (config) => {
    const types = ["vue-modules", "vue", "normal-modules", "normal"];
    types.forEach((type) =>
      addStyleResource(config.module.rule("less").oneOf(type))
    );
  },
};

function addStyleResource(rule) {
  rule
    .use("style-resource")
    .loader("style-resources-loader")
    .options({
      patterns: [path.resolve(__dirname, "./src/static/css/public.less")],
    });
  // 引入全局less------end
}

项目中常用插件

axios用来封装html请求
npm install axios
normalize.css用来初始化页面样式
npm install normalize
weixin-js-sdk用来使用微信api
npm install weixin-js-sdk
style-resources-loader用来对less等预处理,以上示例引入全局less用到
npm i style-resources-loader -D

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值