vue.config.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. ws: false,
  71. changeOrigin: true,
  72. pathRewrite: {
  73. '^./': './'
  74. }
  75. }
  76. },
  77. // public: 'localhost:9999/',
  78. // after: mockServer(),
  79. },
  80. configureWebpack() {
  81. return {
  82. externals: {
  83. AMap: "AMap"
  84. },
  85. module: {
  86. rules: [{
  87. test: /\.mjs$/,
  88. include: /node_modules/,
  89. type: "javascript/auto"
  90. }]
  91. },
  92. resolve: {
  93. alias: {
  94. '@': resolve('src'),
  95. '*': resolve(''),
  96. },
  97. },
  98. plugins: [
  99. new Webpack.ProvidePlugin(providePlugin),
  100. // new UglifyJsPlugin({
  101. // uglifyOptions: {
  102. // output: {
  103. // comments: false, // 去掉注释
  104. // },
  105. // warnings: false,
  106. // compress: {
  107. // drop_console: true,
  108. // drop_debugger: false,
  109. // pure_funcs: ['console.log']//移除console
  110. // }
  111. // }
  112. // })
  113. ],
  114. }
  115. },
  116. chainWebpack(config) {
  117. config.resolve.symlinks(true)
  118. config.module
  119. .rule('svg')
  120. .exclude.add(resolve('src/icons'))
  121. .end()
  122. config.module
  123. .rule('icons')
  124. .test(/\.svg$/)
  125. .include.add(resolve('src/icons'))
  126. .end()
  127. .use('svg-sprite-loader')
  128. .loader('svg-sprite-loader')
  129. .options({
  130. symbolId: 'icon-[name]'
  131. })
  132. .end()
  133. config.when(process.env.NODE_ENV === 'development', (config) => {
  134. config.devtool('source-map')
  135. })
  136. config.when(process.env.NODE_ENV !== 'development', (config) => {
  137. config.performance.set('hints', false)
  138. config.devtool('none')
  139. config.optimization.splitChunks({
  140. chunks: 'all',
  141. cacheGroups: {
  142. libs: {
  143. name: 'vue-admin-beautiful-libs',
  144. test: /[\\/]node_modules[\\/]/,
  145. priority: 10,
  146. chunks: 'initial',
  147. },
  148. },
  149. })
  150. config.module
  151. .rule('images')
  152. .use('image-webpack-loader')
  153. .loader('image-webpack-loader')
  154. .options({
  155. bypassOnDebug: true,
  156. })
  157. .end()
  158. })
  159. if (build7z) {
  160. config.when(process.env.NODE_ENV === 'production', (config) => {
  161. config
  162. .plugin('fileManager')
  163. .use(FileManagerPlugin, [{
  164. onEnd: {
  165. delete: [`./${outputDir}/video`, `./${outputDir}/data`],
  166. archive: [{
  167. source: `./${outputDir}`,
  168. destination: `./${outputDir}/${abbreviation}_${outputDir}_${date}.7z`,
  169. },],
  170. },
  171. },])
  172. .end()
  173. })
  174. }
  175. },
  176. runtimeCompiler: true,
  177. productionSourceMap: false,
  178. css: {
  179. requireModuleExtension: true,
  180. sourceMap: true,
  181. loaderOptions: {
  182. sass: {
  183. data: `
  184. @import "@/assets/css/index.scss";
  185. @import "@/assets/css/global.scss";
  186. `
  187. },
  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. }