vue.config.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* eslint-disable @typescript-eslint/no-var-requires */
  2. const bodyParser = require('body-parser')
  3. const mockServer = require('./src/utils/mock/server');
  4. const { NODE_ENV, VUE_APP_PORT, VUE_APP_MOCK } = process.env;
  5. module.exports = {
  6. publicPath: '/',
  7. outputDir: 'dist',
  8. productionSourceMap: false,
  9. devServer: {
  10. port: VUE_APP_PORT || 8000,
  11. // 配置反向代理
  12. /*
  13. proxy: {
  14. '/api': {
  15. target: '<url>',
  16. ws: true,
  17. changeOrigin: true
  18. },
  19. '/foo': {
  20. target: '<other_url>'
  21. }
  22. },
  23. */
  24. before: function(app, server) {
  25. if(NODE_ENV === 'development' && VUE_APP_MOCK === 'true') {
  26. // parse app.body
  27. // https://expressjs.com/en/4x/api.html#req.body
  28. // create application/json parser
  29. app.use(bodyParser.json());
  30. // create application/x-www-form-urlencoded parser
  31. app.use(bodyParser.urlencoded({ extended: false}));
  32. mockServer(app);
  33. }
  34. }
  35. },
  36. // 修改webpack的配置
  37. configureWebpack: {
  38. // 不需要打包的插件
  39. externals: {
  40. // 'vue': 'Vue',
  41. // 'vue-router': 'VueRouter',
  42. // 'element-ui': 'ELEMENT'
  43. }
  44. },
  45. chainWebpack(config) {
  46. // 内置的 svg Rule 添加 exclude
  47. config.module
  48. .rule('svg')
  49. .exclude.add(/iconsvg/)
  50. .end();
  51. // 添加 svg-sprite-loader Rule
  52. config.module
  53. .rule('svg-sprite-loader')
  54. .test(/.svg$/)
  55. .include.add(/iconsvg/)
  56. .end()
  57. .use('svg-sprite-loader')
  58. .loader('svg-sprite-loader');
  59. // 添加 svgo Rule
  60. config.module
  61. .rule('svgo')
  62. .test(/.svg$/)
  63. .include.add(/iconsvg/)
  64. .end()
  65. .use('svgo-loader')
  66. .loader('svgo-loader')
  67. .options({
  68. // externalConfig 配置特殊不是相对路径,起始路径是根目录
  69. externalConfig: './src/assets/iconsvg/svgo.yml',
  70. });
  71. }
  72. }