vue.config.js 5.8 KB

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