vue.config.js 6.6 KB

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