vue.config.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /**
  2. * @author chuzhixin 1204505056@qq.com
  3. * @description vue.config.js全局配置
  4. */
  5. const path = require('path')
  6. const {
  7. /* baseURL, */
  8. publicPath,
  9. assetsDir,
  10. outputDir,
  11. lintOnSave,
  12. transpileDependencies,
  13. title,
  14. abbreviation,
  15. devPort,
  16. providePlugin,
  17. build7z,
  18. donation,
  19. } = require('./src/config')
  20. const { webpackBarName, webpackBanner, donationConsole } = require('vab-config')
  21. if (donation) donationConsole()
  22. const { version, author } = require('./package.json')
  23. const Webpack = require('webpack')
  24. const WebpackBar = require('webpackbar')
  25. const FileManagerPlugin = require('filemanager-webpack-plugin')
  26. const dayjs = require('dayjs')
  27. const date = dayjs().format('YYYY_M_D')
  28. const time = dayjs().format('YYYY-M-D HH:mm:ss')
  29. process.env.VUE_APP_TITLE = title || '欢迎使用用电后台管理平台!'
  30. process.env.VUE_APP_AUTHOR = author || 'chuzhixin'
  31. process.env.VUE_APP_UPDATE_TIME = time
  32. process.env.VUE_APP_VERSION = version
  33. const resolve = (dir) => {
  34. return path.join(__dirname, dir)
  35. }
  36. // const mockServer = () => {
  37. // if (process.env.NODE_ENV === 'development') {
  38. // return require('./mock/mockServer.js')
  39. // } else {
  40. // return ''
  41. // }
  42. // }
  43. module.exports = {
  44. publicPath,
  45. assetsDir,
  46. outputDir,
  47. lintOnSave,
  48. transpileDependencies,
  49. css: {
  50. loaderOptions: {
  51. sass: {
  52. data: `
  53. @import "@/assets/css/index.scss";
  54. @import "@/assets/css/global.scss";
  55. `
  56. }
  57. }
  58. },
  59. devServer: {
  60. hot: true,
  61. port: devPort,
  62. open: true,
  63. noInfo: false,
  64. overlay: {
  65. warnings: true,
  66. errors: true,
  67. },
  68. // 注释掉的地方是前端配置代理访问后端的示例
  69. proxy: {
  70. // [baseURL]: {
  71. // target: `http://你的后端接口地址`,
  72. // ws: true,
  73. // changeOrigin: true,
  74. // pathRewrite: {
  75. // ["^/" + baseURL]: "",
  76. // },
  77. // },
  78. './': {
  79. target: 'https://qhome.usky.cn/fivapi/',
  80. ws: false,
  81. changeOrigin: true,
  82. pathRewrite: {
  83. '^./': './'
  84. }
  85. }
  86. },
  87. public: 'localhost:9999/',
  88. // after: mockServer(),
  89. },
  90. configureWebpack() {
  91. return {
  92. resolve: {
  93. alias: {
  94. '@': resolve('src'),
  95. '*': resolve(''),
  96. },
  97. },
  98. plugins: [
  99. new Webpack.ProvidePlugin(providePlugin),
  100. new WebpackBar({
  101. name: webpackBarName,
  102. }),
  103. ],
  104. }
  105. },
  106. chainWebpack(config) {
  107. config.resolve.symlinks(true)
  108. config.module
  109. .rule('svg')
  110. .exclude.add(resolve('src/icons'))
  111. .end()
  112. config.module
  113. .rule('icons')
  114. .test(/\.svg$/)
  115. .include.add(resolve('src/icons'))
  116. .end()
  117. .use('svg-sprite-loader')
  118. .loader('svg-sprite-loader')
  119. .options({
  120. symbolId: 'icon-[name]'
  121. })
  122. .end()
  123. config.when(process.env.NODE_ENV === 'development', (config) => {
  124. config.devtool('source-map')
  125. })
  126. config.when(process.env.NODE_ENV !== 'development', (config) => {
  127. config.performance.set('hints', false)
  128. config.devtool('none')
  129. config.optimization.splitChunks({
  130. chunks: 'all',
  131. cacheGroups: {
  132. libs: {
  133. name: 'vue-admin-beautiful-libs',
  134. test: /[\\/]node_modules[\\/]/,
  135. priority: 10,
  136. chunks: 'initial',
  137. },
  138. },
  139. })
  140. config
  141. .plugin('banner')
  142. .use(Webpack.BannerPlugin, [`${webpackBanner}${time}`])
  143. .end()
  144. config.module
  145. .rule('images')
  146. .use('image-webpack-loader')
  147. .loader('image-webpack-loader')
  148. .options({
  149. bypassOnDebug: true,
  150. })
  151. .end()
  152. })
  153. if (build7z) {
  154. config.when(process.env.NODE_ENV === 'production', (config) => {
  155. config
  156. .plugin('fileManager')
  157. .use(FileManagerPlugin, [{
  158. onEnd: {
  159. delete: [`./${outputDir}/video`, `./${outputDir}/data`],
  160. archive: [{
  161. source: `./${outputDir}`,
  162. destination: `./${outputDir}/${abbreviation}_${outputDir}_${date}.7z`,
  163. },],
  164. },
  165. },])
  166. .end()
  167. })
  168. }
  169. },
  170. runtimeCompiler: true,
  171. productionSourceMap: false,
  172. css: {
  173. requireModuleExtension: true,
  174. sourceMap: true,
  175. loaderOptions: {
  176. less: {
  177. lessOptions: {
  178. javascriptEnabled: true,
  179. modifyVars: {
  180. 'vab-color-blue': '#1890ff',
  181. 'vab-margin': '20px',
  182. 'vab-padding': '20px',
  183. 'vab-header-height': '54px',
  184. 'vab-breadcrumb-height': '37px',
  185. 'vab-public-height': 'calc(100vh - 130px)',
  186. },
  187. },
  188. },
  189. },
  190. },
  191. }