vue.config.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. const path = require('path');
  2. const envConfig = require('./src/config');
  3. function resolve(dir) {
  4. return path.join(__dirname, dir); // path.join(__dirname)设置绝对路径
  5. }
  6. const proxyAgent = {
  7. target: envConfig.baseApi,
  8. ws: true, // 代理的WebSockets
  9. changeOrigin: true, // 允许websockets跨域
  10. logLevel: 'debug',
  11. pathRewrite: {}
  12. };
  13. module.exports = {
  14. publicPath: '/czc-commandCenter',
  15. productionSourceMap: false,
  16. filenameHashing: false,
  17. chainWebpack: (config) => {
  18. // 配置别名
  19. config.resolve.alias
  20. .set('@', resolve('src'))
  21. .set('@assets', resolve('src/assets'))
  22. .set('@views', resolve('src/views'))
  23. .set('@components', resolve('src/components'))
  24. .set('@utils', resolve('src/utils'));
  25. // 配置style px->vm
  26. config.module
  27. .rule('vue')
  28. .test(/\.vue$/)
  29. .use('style-vw-loader')
  30. .loader('style-vw-loader')
  31. .options({
  32. viewportWidth: 1920 //传参
  33. });
  34. // // // 配置每次打包浏览器缓存文件名的随机性
  35. // const filename = path.posix.join('js', `${new Date().getTime()}_[name].js`);
  36. // config.mode('production').devtool(false).output.filename(filename).chunkFilename(filename);
  37. },
  38. // 配置全局样式变量
  39. css: {
  40. loaderOptions: {
  41. postcss: {
  42. plugins: [
  43. require('postcss-pxtorem')({
  44. rootValue: 100, // 换算的基数
  45. selectorBlackList: ['weui', 'mu'], // 忽略转换正则匹配项
  46. propList: ['*']
  47. })
  48. ]
  49. }
  50. }
  51. // extract: {
  52. // // 打包后css文件名称添加时间戳
  53. // filename: `css/[name].${new Date().getTime()}.css`,
  54. // chunkFilename: `css/chunk.[id].${new Date().getTime()}.css`
  55. // }
  56. },
  57. devServer: {
  58. host: '0.0.0.0', // can be overwritten by process.env.HOST
  59. port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
  60. https: false, // https:{type:Boolean}
  61. open: false, // 配置自动启动浏览器 open: 'Google Chrome'-默认启动谷歌
  62. // 配置多个代理
  63. proxy: {
  64. '/czc-user-auth': {
  65. target: envConfig.baseApi,
  66. ws: true, // 代理的WebSockets
  67. changeOrigin: true, // 允许websockets跨域
  68. pathRewrite: {
  69. // "^/czc-user-auth": ""
  70. }
  71. },
  72. '/czc-user-center': {
  73. target: envConfig.baseApi,
  74. ws: true, // 代理的WebSockets
  75. changeOrigin: true, // 允许websockets跨域
  76. logLevel: 'debug',
  77. pathRewrite: {
  78. // "^/czc-user-center": ""
  79. }
  80. },
  81. '/czc-community': {
  82. target: envConfig.baseApi,
  83. ws: true, // 代理的WebSockets
  84. changeOrigin: true, // 允许websockets跨域
  85. logLevel: 'debug',
  86. pathRewrite: {
  87. // "^/czc-community": ""
  88. }
  89. },
  90. '/czc-message': {
  91. target: envConfig.baseApi,
  92. ws: true, // 代理的WebSockets
  93. changeOrigin: true, // 允许websockets跨域
  94. logLevel: 'debug',
  95. pathRewrite: {
  96. // "^/czc-message": ""
  97. }
  98. },
  99. '/czc-charge': {
  100. target: envConfig.baseApi,
  101. ws: true, // 代理的WebSockets
  102. changeOrigin: true, // 允许websockets跨域
  103. logLevel: 'debug',
  104. pathRewrite: {
  105. // "^/czc-charge": ""
  106. }
  107. },
  108. '/operation-manager': {
  109. target: envConfig.baseApi,
  110. ws: true, // 代理的WebSockets
  111. changeOrigin: true, // 允许websockets跨域
  112. logLevel: 'debug',
  113. pathRewrite: {
  114. // "^/operation-manager": ""
  115. }
  116. },
  117. '/czc-energy': {
  118. target: envConfig.baseApi,
  119. ws: true, // 代理的WebSockets
  120. changeOrigin: true, // 允许websockets跨域
  121. logLevel: 'debug',
  122. pathRewrite: {
  123. // "^/zoniot-water": ""
  124. }
  125. },
  126. '/card': {
  127. target: envConfig.readCard,
  128. ws: true, // 代理的WebSockets
  129. changeOrigin: true, // 允许websockets跨域
  130. logLevel: 'debug',
  131. pathRewrite: {
  132. // '^/card': ""
  133. }
  134. },
  135. '/czc-gate-web': proxyAgent
  136. },
  137. overlay: {
  138. warnings: false,
  139. errors: false
  140. }
  141. },
  142. pluginOptions: {
  143. 'postcss-import': {},
  144. 'postcss-url': {},
  145. 'postcss-aspect-ratio-mini': {},
  146. 'postcss-write-svg': {
  147. utf8: false
  148. },
  149. 'postcss-cssnext': {},
  150. 'postcss-px-to-viewport': {
  151. viewportWidth: 1920, // 视窗的宽度,对应的是我们设计稿的宽度,移动端一般是750,如果是pc端那就是类似1920这样的尺寸
  152. viewportHeight: 1080, // 视窗的高度,移动端一般指定1334,也可以不配置
  153. unitPrecision: 3, // 指定`px`转换为视窗单位值的小数位数(很多时候无法整除)
  154. viewportUnit: 'vw', // 指定需要转换成的视窗单位,建议使用vw
  155. // selectorBlackList: ['.ignore', '.hairlines'], // 指定不转换为视窗单位的类,可以自定义,可以无限添加,建议定义一至两个通用的类名
  156. minPixelValue: 1, // 小于或等于`1px`不转换为视窗单位,你也可以设置为你想要的值
  157. mediaQuery: false // 允许在媒体查询中转换`px`
  158. },
  159. 'postcss-viewport-units': {},
  160. cssnano: {
  161. preset: 'default', // 设置成default将不会启用autoprefixer
  162. 'postcss-zindex': false
  163. }
  164. },
  165. lintOnSave: false
  166. };