vue.config.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * @Author: zouwenying
  3. * @Date: 2020-10-21 18:14:35
  4. * @LastEditTime: 2021-04-27 17:28:49
  5. * @LastEditors: zwy
  6. * @Description: In User Settings Edit
  7. * @FilePath: \vue-manage-system-master\vue.config.js
  8. */
  9. const path = require('path');
  10. const envConfig = require('./src/config');
  11. function resolve(dir) {
  12. return path.join(__dirname, dir); // path.join(__dirname)设置绝对路径
  13. }
  14. module.exports = {
  15. publicPath: process.env.NODE_ENV === 'sit' ? '/sc-energyMg' : '/',
  16. productionSourceMap: 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. // sass: {
  42. // data: '@import "@/assets/styles/common/px2rem.scss";@import "@/assets/styles/common/mixins.scss";'
  43. // },
  44. // postcss: {
  45. // plugins: [
  46. // require('postcss-pxtorem')({
  47. // rootValue: 100, // 换算的基数
  48. // selectorBlackList: ['weui', 'mu'], // 忽略转换正则匹配项
  49. // propList: ['*']
  50. // })
  51. // ]
  52. // }
  53. // scss: generateLoaders('sass').concat({
  54. // loader: 'sass-resources-loader',
  55. // options: {
  56. // resources: path.relative(__dirname, '../src/assets/css/punlic-style.scss')
  57. // }
  58. // })
  59. }
  60. },
  61. configureWebpack: {
  62. externals: {
  63. vue: 'Vue',
  64. 'vue-router': 'VueRouter',
  65. vuex: 'Vuex',
  66. 'element-ui': 'ELEMENT',
  67. axios: 'axios',
  68. lodash: '_',
  69. dayjs: 'dayjs',
  70. echarts: 'echarts'
  71. }
  72. },
  73. devServer: {
  74. host: '0.0.0.0', // can be overwritten by process.env.HOST
  75. port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
  76. https: false, // https:{type:Boolean}
  77. open: false, // 配置自动启动浏览器 open: 'Google Chrome'-默认启动谷歌
  78. // 配置多个代理
  79. proxy: {
  80. '/sc-user-auth': {
  81. target: envConfig.baseApi,
  82. ws: true, // 代理的WebSockets
  83. changeOrigin: true, // 允许websockets跨域
  84. pathRewrite: {
  85. // "^/sc-user-auth": ""
  86. }
  87. },
  88. '/sc-user-center': {
  89. target: envConfig.baseApi,
  90. ws: true, // 代理的WebSockets
  91. changeOrigin: true, // 允许websockets跨域
  92. logLevel: 'debug',
  93. pathRewrite: {
  94. // "^/sc-user-center": ""
  95. }
  96. },
  97. '/sc-community': {
  98. target: envConfig.baseApi,
  99. ws: true, // 代理的WebSockets
  100. changeOrigin: true, // 允许websockets跨域
  101. logLevel: 'debug',
  102. pathRewrite: {
  103. // "^/sc-community": ""
  104. }
  105. },
  106. '/sc-message': {
  107. target: envConfig.baseApi,
  108. ws: true, // 代理的WebSockets
  109. changeOrigin: true, // 允许websockets跨域
  110. logLevel: 'debug',
  111. pathRewrite: {
  112. // "^/sc-message": ""
  113. }
  114. },
  115. '/sc-charge': {
  116. target: envConfig.baseApi,
  117. ws: true, // 代理的WebSockets
  118. changeOrigin: true, // 允许websockets跨域
  119. logLevel: 'debug',
  120. pathRewrite: {
  121. // "^/sc-charge": ""
  122. }
  123. },
  124. '/sc-energy': {
  125. target: envConfig.baseApi,
  126. ws: true, // 代理的WebSockets
  127. changeOrigin: true, // 允许websockets跨域
  128. logLevel: 'debug',
  129. pathRewrite: {
  130. // "^/sc-charge": ""
  131. }
  132. },
  133. '/operation-manager': {
  134. target: envConfig.baseApi,
  135. ws: true, // 代理的WebSockets
  136. changeOrigin: true, // 允许websockets跨域
  137. logLevel: 'debug',
  138. pathRewrite: {
  139. // "^/operation-manager": ""
  140. }
  141. },
  142. '/zoniot-water': {
  143. target: envConfig.baseApi,
  144. ws: true, // 代理的WebSockets
  145. changeOrigin: true, // 允许websockets跨域
  146. logLevel: 'debug',
  147. pathRewrite: {
  148. // "^/zoniot-water": ""
  149. }
  150. },
  151. }
  152. },
  153. pluginOptions: {
  154. "postcss-import": {},
  155. "postcss-url": {},
  156. "postcss-aspect-ratio-mini": {},
  157. "postcss-write-svg": {
  158. utf8: false
  159. },
  160. "postcss-cssnext": {},
  161. "postcss-px-to-viewport": {
  162. viewportWidth: 1920, // 视窗的宽度,对应的是我们设计稿的宽度,移动端一般是750,如果是pc端那就是类似1920这样的尺寸
  163. viewportHeight: 1080, // 视窗的高度,移动端一般指定1334,也可以不配置
  164. unitPrecision: 3, // 指定`px`转换为视窗单位值的小数位数(很多时候无法整除)
  165. viewportUnit: 'vw', // 指定需要转换成的视窗单位,建议使用vw
  166. // selectorBlackList: ['.ignore', '.hairlines'], // 指定不转换为视窗单位的类,可以自定义,可以无限添加,建议定义一至两个通用的类名
  167. minPixelValue: 1, // 小于或等于`1px`不转换为视窗单位,你也可以设置为你想要的值
  168. mediaQuery: false // 允许在媒体查询中转换`px`
  169. },
  170. "postcss-viewport-units": {},
  171. "cssnano": {
  172. preset: "default", // 设置成default将不会启用autoprefixer
  173. "postcss-zindex": false
  174. }
  175. }
  176. };