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