vue.config.js 6.6 KB

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