vue.config.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 { version, author } = require('./package.json')
  21. const Webpack = require('webpack')
  22. const WebpackBar = require('webpackbar')
  23. const FileManagerPlugin = require('filemanager-webpack-plugin')
  24. const dayjs = require('dayjs')
  25. const date = dayjs().format('YYYY_M_D')
  26. const time = dayjs().format('YYYY-M-D HH:mm:ss')
  27. process.env.VUE_APP_TITLE = title || '欢迎使用用电后台管理平台!'
  28. process.env.VUE_APP_AUTHOR = author || 'chuzhixin'
  29. process.env.VUE_APP_UPDATE_TIME = time
  30. process.env.VUE_APP_VERSION = version
  31. const resolve = (dir) => {
  32. return path.join(__dirname, dir)
  33. }
  34. // const mockServer = () => {
  35. // if (process.env.NODE_ENV === 'development') {
  36. // return require('./mock/mockServer.js')
  37. // } else {
  38. // return ''
  39. // }
  40. // }
  41. const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
  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. disableHostCheck: true,
  58. // 注释掉的地方是前端配置代理访问后端的示例
  59. proxy: {
  60. // [baseURL]: {
  61. // target: `http://你的后端接口地址`,
  62. // ws: true,
  63. // changeOrigin: true,
  64. // pathRewrite: {
  65. // ["^/" + baseURL]: "",
  66. // },
  67. // },
  68. './': {
  69. // target: 'https://qhome.usky.cn/uskypower/',
  70. target: 'http://172.16.120.165:8011/',
  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 UglifyJsPlugin({
  102. // uglifyOptions: {
  103. // output: {
  104. // comments: false, // 去掉注释
  105. // },
  106. // warnings: false,
  107. // compress: {
  108. // drop_console: true,
  109. // drop_debugger: false,
  110. // pure_funcs: ['console.log']//移除console
  111. // }
  112. // }
  113. // })
  114. ],
  115. }
  116. },
  117. chainWebpack(config) {
  118. config.resolve.symlinks(true)
  119. config.module
  120. .rule('svg')
  121. .exclude.add(resolve('src/icons'))
  122. .end()
  123. config.module
  124. .rule('icons')
  125. .test(/\.svg$/)
  126. .include.add(resolve('src/icons'))
  127. .end()
  128. .use('svg-sprite-loader')
  129. .loader('svg-sprite-loader')
  130. .options({
  131. symbolId: 'icon-[name]'
  132. })
  133. .end()
  134. config.when(process.env.NODE_ENV === 'development', (config) => {
  135. config.devtool('source-map')
  136. })
  137. config.when(process.env.NODE_ENV !== 'development', (config) => {
  138. config.performance.set('hints', false)
  139. config.devtool('none')
  140. config.optimization.splitChunks({
  141. chunks: 'all',
  142. cacheGroups: {
  143. libs: {
  144. name: 'vue-admin-beautiful-libs',
  145. test: /[\\/]node_modules[\\/]/,
  146. priority: 10,
  147. chunks: 'initial',
  148. },
  149. },
  150. })
  151. config.module
  152. .rule('images')
  153. .use('image-webpack-loader')
  154. .loader('image-webpack-loader')
  155. .options({
  156. bypassOnDebug: true,
  157. })
  158. .end()
  159. })
  160. if (build7z) {
  161. config.when(process.env.NODE_ENV === 'production', (config) => {
  162. config
  163. .plugin('fileManager')
  164. .use(FileManagerPlugin, [{
  165. onEnd: {
  166. delete: [`./${outputDir}/video`, `./${outputDir}/data`],
  167. archive: [{
  168. source: `./${outputDir}`,
  169. destination: `./${outputDir}/${abbreviation}_${outputDir}_${date}.7z`,
  170. }, ],
  171. },
  172. }, ])
  173. .end()
  174. })
  175. }
  176. },
  177. runtimeCompiler: true,
  178. productionSourceMap: false,
  179. css: {
  180. requireModuleExtension: true,
  181. sourceMap: true,
  182. loaderOptions: {
  183. sass: {
  184. data: `
  185. @import "@/assets/css/index.scss";
  186. @import "@/assets/css/global.scss";
  187. `
  188. },
  189. less: {
  190. lessOptions: {
  191. javascriptEnabled: true,
  192. modifyVars: {
  193. 'vab-color-blue': '#1890ff',
  194. 'vab-margin': '15px',
  195. 'vab-padding': '15px',
  196. 'vab-header-height': '60px',
  197. 'vab-breadcrumb-height': '37px',
  198. 'vab-public-height': 'calc(100vh - 130px)',
  199. },
  200. },
  201. },
  202. },
  203. },
  204. }