vue.config.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. proxy: {
  46. "/api": {
  47. target: "http://localhost:3000",
  48. bypass: function(req, res) {
  49. if (req.headers.accept.indexOf("html") !== -1) {
  50. console.log("Skipping proxy for browser request.");
  51. return "/index.html";
  52. } else if (process.env.MOCK !== "none") {
  53. const name = req.path
  54. .split("/api/")[1]
  55. .split("/")
  56. .join("_");
  57. const mock = require(`./mock/${name}`);
  58. const result = mock(req.method);
  59. delete require.cache[require.resolve(`./mock/${name}`)];
  60. return res.send(result);
  61. }
  62. }
  63. }
  64. }
  65. }
  66. };