vue.config.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const path = require("path");
  2. const AntDesignThemePlugin = require("antd-theme-webpack-plugin");
  3. const options = {
  4. antDir: path.join(__dirname, "./node_modules/ant-design-vue"),
  5. stylesDir: path.join(__dirname, "./src"),
  6. varFile: path.join(
  7. __dirname,
  8. "./node_modules/ant-design-vue/lib/style/themes/default.less"
  9. ),
  10. mainLessFile: "",
  11. themeVariables: ["@primary-color"],
  12. generateOnce: false
  13. };
  14. const themePlugin = new AntDesignThemePlugin(options);
  15. module.exports = {
  16. css: {
  17. loaderOptions: {
  18. less: {
  19. modifyVars: {
  20. "primary-color": "#1DA57A"
  21. },
  22. javascriptEnabled: true
  23. }
  24. }
  25. },
  26. configureWebpack: {
  27. plugins: [themePlugin]
  28. },
  29. chainWebpack: config => {
  30. const svgRule = config.module.rule("svg");
  31. // 清除已有的所有 loader。
  32. // 如果你不这样做,接下来的 loader 会附加在该规则现有的 loader 之后。
  33. svgRule.uses.clear();
  34. // 添加要替换的 loader
  35. svgRule.use("vue-svg-loader").loader("vue-svg-loader");
  36. },
  37. devServer: {
  38. proxy: {
  39. "/api": {
  40. target: "http://localhost:3000",
  41. bypass: function(req, res) {
  42. if (req.headers.accept.indexOf("html") !== -1) {
  43. console.log("Skipping proxy for browser request.");
  44. return "/index.html";
  45. } else if (process.env.MOCK !== "none") {
  46. const name = req.path
  47. .split("/api/")[1]
  48. .split("/")
  49. .join("_");
  50. const mock = require(`./mock/${name}`);
  51. const result = mock(req.method);
  52. delete require.cache[require.resolve(`./mock/${name}`)];
  53. return res.send(result);
  54. }
  55. }
  56. }
  57. }
  58. }
  59. };