vue.config.js 2.2 KB

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