vue.config.js 5.5 KB

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