vue.config.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. const path = require('path');
  2. const postcssPxToViewport = require('./postcss.config');
  3. const vueSrc = 'src';
  4. const CDN_URL = process.env.CDN_URL || '';
  5. module.exports = {
  6. publicPath:
  7. process.env.NODE_ENV === 'production' ? (CDN_URL ? CDN_URL : '/') : '/',
  8. assetsDir: 'static',
  9. css: {
  10. loaderOptions: {
  11. // 给 less-loader 传递 Less.js 相关选项
  12. less: {
  13. lessOptions: {
  14. // javascriptEnabled: true,
  15. },
  16. additionalData: `@import "@/styles/common.less";`,
  17. },
  18. // scss: {
  19. // // prependData: [path.resolve(__dirname, './src/uni.scss')],
  20. // sassOptions: {
  21. // additionalData: `@import "~@/uni.scss";`
  22. // }
  23. // },
  24. scss: {
  25. additionalData: `@import "~@/uni.scss";`,
  26. },
  27. },
  28. },
  29. pluginOptions: {
  30. 'style-resources-loader': {
  31. preProcessor: 'less',
  32. patterns: [path.resolve(__dirname, './src/styles/common.less')],
  33. },
  34. },
  35. chainWebpack: (config) => {
  36. config.module
  37. .rule('vue')
  38. .test(/\.vue$/)
  39. .use('postcss-style-px-to-viewport')
  40. .loader('postcss-style-px-to-viewport')
  41. .options(postcssPxToViewport.plugins['postcss-px-to-viewport'])
  42. .end();
  43. config
  44. .plugin('html')
  45. .tap((args) => {
  46. args[0].title = '临时停车';
  47. return args;
  48. })
  49. .end();
  50. config.module
  51. .rule('images') //.test(/\.(png|jpe?g|gif|svg)(\?.*)?$/)
  52. .use('url-loader')
  53. .tap((args) => {
  54. const newArgs = Object.assign({}, args, {
  55. limit: 4096,
  56. // 这里重要,publicPath 配置给url-loader 会不生效,必须配置到fallback里传递给file-loader
  57. fallback: {
  58. loader: 'file-loader',
  59. options: {
  60. name: '[name].[hash:8].[ext]',
  61. publicPath:
  62. process.env.NODE_ENV === 'production'
  63. ? CDN_URL + '/static/img'
  64. : '/static/img',
  65. outputPath: 'static/img',
  66. },
  67. },
  68. });
  69. return newArgs;
  70. })
  71. .end();
  72. },
  73. configureWebpack: {
  74. resolve: {
  75. alias: {
  76. '@': path.join(__dirname, vueSrc),
  77. },
  78. },
  79. },
  80. devServer: {
  81. proxy: {
  82. '/profileApi': {
  83. target: 'https://qa-apim.kerryplus.com/c/api', //代理地址,这里设置的地址会代替axios中设置的baseURL
  84. changeOrigin: true, // 如果接口跨域,需要进行这个参数配置
  85. //ws: true, // proxy websockets
  86. //pathRewrite方法重写url
  87. pathRewrite: {
  88. '^/profileApi': '',
  89. //pathRewrite: {'^/api': '/'} 重写之后url为 http://192.168.1.16:8085/xxxx
  90. //pathRewrite: {'^/api': '/api'} 重写之后url为 http://192.168.1.16:8085/api/xxxx
  91. },
  92. },
  93. '/qaPayment': {
  94. target: 'https://qa-apim.kerryplus.com/c/api/payment/v1', //代理地址,这里设置的地址会代替axios中设置的baseURL
  95. changeOrigin: true, // 如果接口跨域,需要进行这个参数配置
  96. //ws: true, // proxy websockets
  97. //pathRewrite方法重写url
  98. pathRewrite: {
  99. '^/qaPayment': '',
  100. //pathRewrite: {'^/api': '/'} 重写之后url为 http://192.168.1.16:8085/xxxx
  101. //pathRewrite: {'^/api': '/api'} 重写之后url为 http://192.168.1.16:8085/api/xxxx
  102. },
  103. },
  104. },
  105. },
  106. };