vue.config.js 3.4 KB

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