vue.config.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /**
  2. * @description vue.config.js全局配置
  3. */
  4. const path = require('path')
  5. const {
  6. /* baseURL, */
  7. publicPath,
  8. assetsDir,
  9. outputDir,
  10. lintOnSave,
  11. transpileDependencies,
  12. title,
  13. abbreviation,
  14. devPort,
  15. providePlugin,
  16. build7z,
  17. webpackBarName,
  18. } = require('./src/config')
  19. const { version, author } = require('./package.json')
  20. const Webpack = require('webpack')
  21. const WebpackBar = require('webpackbar')
  22. const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
  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. module.exports = {
  42. publicPath,
  43. assetsDir,
  44. outputDir,
  45. lintOnSave,
  46. transpileDependencies,
  47. devServer: {
  48. hot: true,
  49. port: devPort,
  50. open: true,
  51. noInfo: false,
  52. overlay: {
  53. warnings: true,
  54. errors: true,
  55. },
  56. disableHostCheck: true,
  57. // 注释掉的地方是前端配置代理访问后端的示例
  58. proxy: {
  59. // [baseURL]: {
  60. // target: `http://你的后端接口地址`,
  61. // ws: true,
  62. // changeOrigin: true,
  63. // pathRewrite: {
  64. // ["^/" + baseURL]: "",
  65. // },
  66. // },
  67. './': {
  68. target: 'https://qhome.usky.cn/uskypower/',
  69. ws: false,
  70. changeOrigin: true,
  71. pathRewrite: {
  72. '^./': './',
  73. },
  74. },
  75. },
  76. // public: 'localhost:9999/',
  77. // after: mockServer(),
  78. },
  79. configureWebpack() {
  80. return {
  81. externals: {
  82. AMap: 'AMap',
  83. },
  84. module: {
  85. rules: [
  86. {
  87. test: /\.mjs$/,
  88. include: /node_modules/,
  89. type: 'javascript/auto',
  90. },
  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. // new UglifyJsPlugin({
  105. // uglifyOptions: {
  106. // output: {
  107. // comments: false, // 去掉注释
  108. // },
  109. // warnings: false,
  110. // compress: {
  111. // drop_console: true,
  112. // drop_debugger: false,
  113. // pure_funcs: ['console.log']//移除console
  114. // }
  115. // }
  116. // })
  117. ],
  118. }
  119. },
  120. chainWebpack(config) {
  121. config.resolve.symlinks(true)
  122. config.module.rule('svg').exclude.add(resolve('src/icons')).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. {
  166. onEnd: {
  167. delete: [`./${outputDir}/video`, `./${outputDir}/data`],
  168. archive: [
  169. {
  170. source: `./${outputDir}`,
  171. destination: `./${outputDir}/${abbreviation}_${outputDir}_${date}.7z`,
  172. },
  173. ],
  174. },
  175. },
  176. ])
  177. .end()
  178. })
  179. }
  180. },
  181. runtimeCompiler: true,
  182. productionSourceMap: false,
  183. css: {
  184. requireModuleExtension: true,
  185. sourceMap: true,
  186. loaderOptions: {
  187. sass: {
  188. // additionalData: `
  189. // @import "@/assets/css/index.scss";
  190. // @import "@/assets/css/global.scss";
  191. // `,
  192. },
  193. less: {
  194. lessOptions: {
  195. javascriptEnabled: true,
  196. modifyVars: {
  197. 'vab-color-blue': '#1890ff',
  198. 'vab-margin': '15px',
  199. 'vab-padding': '15px',
  200. 'vab-header-height': '60px',
  201. 'vab-breadcrumb-height': '37px',
  202. 'vab-public-height': 'calc(100vh - 130px)',
  203. },
  204. },
  205. },
  206. },
  207. },
  208. }