vue.config.js 6.0 KB

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