vue.config.js 6.3 KB

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