vue.config.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. requireModuleExtension: true,
  51. sourceMap: true,
  52. loaderOptions: {
  53. sass: {
  54. data: `
  55. @import "@/assets/css/index.scss";
  56. @import "@/assets/css/global.scss";
  57. `
  58. },
  59. less: {
  60. lessOptions: {
  61. javascriptEnabled: true,
  62. modifyVars: {
  63. 'vab-color-blue': '#1890ff',
  64. 'vab-margin': '15px',
  65. 'vab-padding': '15px',
  66. 'vab-header-height': '60px',
  67. 'vab-breadcrumb-height': '37px',
  68. 'vab-public-height': 'calc(100vh - 130px)',
  69. },
  70. },
  71. },
  72. }
  73. },
  74. devServer: {
  75. hot: true,
  76. port: devPort,
  77. open: true,
  78. noInfo: false,
  79. overlay: {
  80. warnings: true,
  81. errors: true,
  82. },
  83. disableHostCheck: true,
  84. // 注释掉的地方是前端配置代理访问后端的示例
  85. proxy: {
  86. // [baseURL]: {
  87. // target: `http://你的后端接口地址`,
  88. // ws: true,
  89. // changeOrigin: true,
  90. // pathRewrite: {
  91. // ["^/" + baseURL]: "",
  92. // },
  93. // },
  94. './': {
  95. target: 'https://qhome.usky.cn/uskypower/',
  96. ws: false,
  97. changeOrigin: true,
  98. pathRewrite: {
  99. '^./': './'
  100. }
  101. }
  102. },
  103. // public: 'localhost:9999/',
  104. // after: mockServer(),
  105. },
  106. configureWebpack() {
  107. return {
  108. externals: {
  109. AMap: "AMap"
  110. },
  111. module: {
  112. rules: [{
  113. test: /\.mjs$/,
  114. include: /node_modules/,
  115. type: "javascript/auto"
  116. }]
  117. },
  118. resolve: {
  119. alias: {
  120. '@': resolve('src'),
  121. '*': resolve(''),
  122. },
  123. },
  124. plugins: [
  125. new Webpack.ProvidePlugin(providePlugin),
  126. new WebpackBar({
  127. name: webpackBarName,
  128. }),
  129. ],
  130. }
  131. },
  132. chainWebpack(config) {
  133. config.resolve.symlinks(true)
  134. config.module
  135. .rule('svg')
  136. .exclude.add(resolve('src/icons'))
  137. .end()
  138. config.module
  139. .rule('icons')
  140. .test(/\.svg$/)
  141. .include.add(resolve('src/icons'))
  142. .end()
  143. .use('svg-sprite-loader')
  144. .loader('svg-sprite-loader')
  145. .options({
  146. symbolId: 'icon-[name]'
  147. })
  148. .end()
  149. config.when(process.env.NODE_ENV === 'development', (config) => {
  150. config.devtool('source-map')
  151. })
  152. config.when(process.env.NODE_ENV !== 'development', (config) => {
  153. config.performance.set('hints', false)
  154. config.devtool('none')
  155. config.optimization.splitChunks({
  156. chunks: 'all',
  157. cacheGroups: {
  158. libs: {
  159. name: 'vue-admin-beautiful-libs',
  160. test: /[\\/]node_modules[\\/]/,
  161. priority: 10,
  162. chunks: 'initial',
  163. },
  164. },
  165. })
  166. config
  167. .plugin('banner')
  168. .use(Webpack.BannerPlugin, [`${webpackBanner}${time}`])
  169. .end()
  170. config.module
  171. .rule('images')
  172. .use('image-webpack-loader')
  173. .loader('image-webpack-loader')
  174. .options({
  175. bypassOnDebug: true,
  176. })
  177. .end()
  178. })
  179. if (build7z) {
  180. config.when(process.env.NODE_ENV === 'production', (config) => {
  181. config
  182. .plugin('fileManager')
  183. .use(FileManagerPlugin, [{
  184. onEnd: {
  185. delete: [`./${outputDir}/video`, `./${outputDir}/data`],
  186. archive: [{
  187. source: `./${outputDir}`,
  188. destination: `./${outputDir}/${abbreviation}_${outputDir}_${date}.7z`,
  189. },],
  190. },
  191. },])
  192. .end()
  193. })
  194. }
  195. },
  196. runtimeCompiler: true,
  197. productionSourceMap: false,
  198. }