vue.config.js 2.56 KB
// const fs = require("fs");
// const readlineSync = require("readline-sync");

// const readline = require("readline");
// // 获取当前版本信息
// const vinfopath = "./public/js/version.json";
// var vinfo = fs.readFileSync(vinfopath, "utf8");
// console.log(vinfo);
// // 新版本设置

// var versionnum = readlineSync.question("new Vsersion:");
// var reg = /\d.\d.\d/;
// if (versionnum != "" && reg.test(versionnum)) {
//   var varr = versionnum.split(".");
//   var oldv = JSON.parse(vinfo).version.split(".");
//   if (varr[0] >= oldv[0] && varr[1] >= oldv[1] && varr[2] > oldv[2]) {
//     console.log(versionnum);
//   } else {
//     throw "新版本号必须大于旧版本号!";
//   }
// } else {
//   throw "版本号错误";
// }

// var info = readlineSync.question("EditInfo:", "utf8", {
//   encoding:"UTF-8",
//   hideEchoBack: true // The typed text on screen is hidden by `*` (default).
// });
// var buginfo = readlineSync.question("BugInfo:", "utf8", {
//   encoding:"utf-8",
//   hideEchoBack: true // The typed text on screen is hidden by `*` (default).
// });
// console.log(buginfo)
// var verinfo = fs.openSync(vinfopath, "w+");
// var obj = {
//   version: versionnum,
//   Info: info,
//   Bug: buginfo,
//   date: new Date()
// };
// var options = { encoding: 'UTF-8', mode: 438 /*=0666*/, flag: 'w' };
// fs.writeFileSync(verinfo, JSON.stringify(obj), options);
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
  .BundleAnalyzerPlugin;

module.exports = {
  lintOnSave: false,
  publicPath: process.env.NODE_ENV === "production" ? "./" : "/",
  // ...
  css: {
    loaderOptions: {
      sass: {
        prependData: '@import "@/assets/scss/common.scss";'
      }
    }
  },
  chainWebpack: config => {
    if (process.env.use_analyzer) {     // 分析
        config
            .plugin('webpack-bundle-analyzer')
            .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
      }
  },
  pluginOptions: {
    // 第三方插件配置
  },
  devServer: {
    proxy: {
      "/api": {
        target: "http://vion-panda.51vip.biz:52510", // 要访问的接口域名
        ws: true, // 是否启用websockets
        changeOrigin: true, //开启代理:在本地会创建一个虚拟服务端,然后发送请求的数据,并同时接收请求的数据,这样服务端和服务端进行数据的交互就不会有跨域问题
        pathRewrite: {
          "^/api": "" //这里理解成用'/api'代替target里面的地址,比如我要调用'http://40.00.100.100:3002/user/add',直接写'/api/user/add'即可
        }
      }
    }
  }
};