vue.config.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. 'use strict'
  2. const path = require('path')
  3. // 获取git版本信息
  4. const fs = require("fs")
  5. const gitHEAD = fs.readFileSync('.git/HEAD', 'utf-8').trim()
  6. const ref = gitHEAD.split(': ')[1]
  7. const develop = gitHEAD.split('/')[2]
  8. const gitVersion = fs.readFileSync('.git/' + ref, 'utf-8').trim()
  9. const buildEdition = develop + ': ' + gitVersion
  10. const myDate = new Date();
  11. const buildTime = myDate.getFullYear() +'-'+ (myDate.getMonth()+1) +'-'+ myDate.getDate() +' '+ myDate.getHours() +':'+ myDate.getMinutes();
  12. const buildUser = fs.readFileSync('.git/logs/HEAD', 'utf-8').match(/<(\S*)>/)[1].match(/\+(\S*)@/)[1]
  13. function resolve(dir) {
  14. return path.join(__dirname, dir)
  15. }
  16. const name = process.env.VUE_APP_TITLE || '实验室安全管理系统' // 网页标题
  17. const port = process.env.port || process.env.npm_config_port || 80 // 端口
  18. // vue.mqttConfig.js明
  19. //官方vue.mqttConfig.js档 https://cli.vuejs.org/zh/config/#css-loaderoptions
  20. // 这里只列一部分,具体配置参考文档
  21. module.exports = {
  22. // 部署生产环境和开发环境下的URL。
  23. // 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上
  24. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  25. publicPath: process.env.NODE_ENV === "production" ? "./" : "./",
  26. // 在npm run build 或 yarn build 时 ,生成文件的目录名称(要和baseUrl的生产环境路径一致)(默认dist)
  27. outputDir: 'dist',
  28. // 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下)
  29. assetsDir: 'static',
  30. // 是否开启eslint保存检测,有效值:ture | false | 'error'
  31. lintOnSave: process.env.NODE_ENV === 'development',
  32. // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
  33. productionSourceMap: false,
  34. // webpack-dev-server 相关配置
  35. devServer: {
  36. host: '0.0.0.0',
  37. port: port,
  38. open: true,
  39. proxy: {
  40. // detail: https://cli.vuejs.org/config/#devserver-proxy
  41. [process.env.VUE_APP_BASE_API]: {
  42. target: `http://localhost:8080`,
  43. changeOrigin: true,
  44. pathRewrite: {
  45. ['^' + process.env.VUE_APP_BASE_API]: ''
  46. }
  47. }
  48. },
  49. disableHostCheck: true
  50. },
  51. //修改了sass版本从1.32.0 升级至1.39.0 以解决页面小图标偶发性乱码问题 以下css代码为同步增加
  52. css: {
  53. loaderOptions: {
  54. sass: {
  55. sassOptions: {
  56. outputStyle: 'expanded'
  57. }
  58. }
  59. }
  60. },
  61. configureWebpack: {
  62. name: name,
  63. resolve: {
  64. alias: {
  65. '@': resolve('src')
  66. }
  67. }
  68. },
  69. chainWebpack(config) {
  70. config.plugins.delete('preload') // TODO: need test
  71. config.plugins.delete('prefetch') // TODO: need test
  72. // 图片转base64
  73. // const imagesRule = config.module.rule('images');
  74. // imagesRule.uses.clear() //清除原本的images loader配置
  75. // imagesRule
  76. // .test(/\.(jpg|gif|png|svg)$/)
  77. // .exclude
  78. // .add(path.join(__dirname,"../node_modules"))//去除node_modules里的图片转base64配置
  79. // .end()
  80. // .use('url-loader')
  81. // .loader('url-loader')
  82. // .options({name:"img/[name].[hash:8].[ext]",limit: 1})
  83. // set svg-sprite-loader
  84. config.module
  85. .rule('svg')
  86. .exclude.add(resolve('src/assets/icons'))
  87. .end()
  88. config.module
  89. .rule('icons')
  90. .test(/\.svg$/)
  91. .include.add(resolve('src/assets/icons'))
  92. .end()
  93. .use('svg-sprite-loader')
  94. .loader('svg-sprite-loader')
  95. .options({
  96. symbolId: 'icon-[name]'
  97. })
  98. .end()
  99. config
  100. .when(process.env.NODE_ENV !== 'development',
  101. config => {
  102. //标记打包时间与当前git版本信息
  103. config.plugin('html').tap(args => {
  104. args[0].buildUser = buildUser;
  105. args[0].buildTime = buildTime;
  106. args[0].buildEdition = buildEdition;
  107. args[0].minify.removeComments = false;
  108. return args
  109. })
  110. config
  111. .plugin('ScriptExtHtmlWebpackPlugin')
  112. .after('html')
  113. .use('script-ext-html-webpack-plugin', [{
  114. // `runtime` must same as runtimeChunk name. default is `runtime`
  115. inline: /runtime\..*\.js$/
  116. }])
  117. .end()
  118. config
  119. .optimization.splitChunks({
  120. chunks: 'all',
  121. cacheGroups: {
  122. libs: {
  123. name: 'chunk-libs',
  124. test: /[\\/]node_modules[\\/]/,
  125. priority: 10,
  126. chunks: 'initial' // only package third parties that are initially dependent
  127. },
  128. elementUI: {
  129. name: 'chunk-elementUI', // split elementUI into a single package
  130. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  131. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  132. },
  133. echarts: {
  134. name: 'chunk-echarts',
  135. priority: 20,
  136. test: /[\\/]node_modules[\\/]_?echarts(.*)/
  137. },
  138. flv: {
  139. name: 'chunk-flv',
  140. priority: 20,
  141. test: /[\\/]node_modules[\\/]_?flv(.*)/
  142. },
  143. jsBeautify: {
  144. name: 'chunk-vue-js-beautify',
  145. priority: 20,
  146. test: /[\\/]node_modules[\\/]_?js-beautify(.*)/
  147. },
  148. jsencrypt: {
  149. name: 'chunk-vue-jsencrypt',
  150. priority: 20,
  151. test: /[\\/]node_modules[\\/]_?jsencrypt(.*)/
  152. },
  153. api: {
  154. name: 'chunk-api',
  155. test: resolve('src/api'), // can customize your rules
  156. priority: 0,
  157. minSize: 0,
  158. minChunks: 1,
  159. enforce:true,
  160. reuseExistingChunk: true
  161. },
  162. assets: {
  163. name: 'chunk-assets',
  164. test: resolve('src/assets'), // can customize your rules
  165. priority: 0,
  166. minSize: 0,
  167. minChunks: 1,
  168. enforce:true,
  169. reuseExistingChunk: true
  170. },
  171. commons: {
  172. name: 'chunk-commons',
  173. test: resolve('src/components'), // can customize your rules
  174. priority: 0,
  175. minSize: 0,
  176. minChunks: 1,
  177. enforce:true,
  178. reuseExistingChunk: true
  179. },
  180. directive: {
  181. name: 'chunk-directive',
  182. test: resolve('src/directive'), // can customize your rules
  183. priority: 0,
  184. minSize: 0,
  185. minChunks: 1,
  186. enforce:true,
  187. reuseExistingChunk: true
  188. },
  189. utils: {
  190. name: 'chunk-utils',
  191. test: resolve('src/utils'), // can customize your rules
  192. priority: 0,
  193. minSize: 0,
  194. minChunks: 1,
  195. enforce:true,
  196. reuseExistingChunk: true
  197. },
  198. comprehensive: {
  199. name: 'chunk-comprehensive',
  200. test: resolve('src/views/comprehensive'), // can customize your rules
  201. priority: 0,
  202. minSize: 0,
  203. minChunks: 1,
  204. enforce:true,
  205. reuseExistingChunk: true
  206. },
  207. creditViolation: {
  208. name: 'chunk-creditViolation',
  209. test: resolve('src/views/creditViolation'), // can customize your rules
  210. priority: 0,
  211. minSize: 0,
  212. minChunks: 1,
  213. enforce:true,
  214. reuseExistingChunk: true
  215. },
  216. dashboard: {
  217. name: 'chunk-dashboard',
  218. test: resolve('src/views/dashboard'), // can customize your rules
  219. priority: 0,
  220. minSize: 0,
  221. minChunks: 1,
  222. enforce:true,
  223. reuseExistingChunk: true
  224. },
  225. emergencyManagement: {
  226. name: 'chunk-emergencyManagement',
  227. test: resolve('src/views/emergencyManagement'), // can customize your rules
  228. priority: 0,
  229. minSize: 0,
  230. minChunks: 1,
  231. enforce:true,
  232. reuseExistingChunk: true
  233. },
  234. gasManage3_0: {
  235. name: 'chunk-gasManage3_0',
  236. test: resolve('src/views/gasManage3_0'), // can customize your rules
  237. priority: 0,
  238. minSize: 0,
  239. minChunks: 1,
  240. enforce:true,
  241. reuseExistingChunk: true
  242. },
  243. gasManage_syd: {
  244. name: 'chunk-gasManage_syd',
  245. test: resolve('src/views/gasManage_syd'), // can customize your rules
  246. priority: 0,
  247. minSize: 0,
  248. minChunks: 1,
  249. enforce:true,
  250. reuseExistingChunk: true
  251. },
  252. hazardManagement: {
  253. name: 'chunk-hazardManagement',
  254. test: resolve('src/views/hazardManagement'), // can customize your rules
  255. priority: 0,
  256. minSize: 0,
  257. minChunks: 1,
  258. enforce:true,
  259. reuseExistingChunk: true
  260. },
  261. hierarchicalControl: {
  262. name: 'chunk-hierarchicalControl',
  263. test: resolve('src/views/hierarchicalControl'), // can customize your rules
  264. priority: 0,
  265. minSize: 0,
  266. minChunks: 1,
  267. enforce:true,
  268. reuseExistingChunk: true
  269. },
  270. medicUniversity_3_1: {
  271. name: 'chunk-medicUniversity-3_1',
  272. test: resolve('src/views/medicUniversity-3_1'), // can customize your rules
  273. priority: 0,
  274. minSize: 0,
  275. minChunks: 1,
  276. enforce:true,
  277. reuseExistingChunk: true
  278. },
  279. mine: {
  280. name: 'chunk-mine',
  281. test: resolve('src/views/mine'), // can customize your rules
  282. priority: 0,
  283. minSize: 0,
  284. minChunks: 1,
  285. enforce:true,
  286. reuseExistingChunk: true
  287. },
  288. oneKeyOutfire: {
  289. name: 'chunk-oneKeyOutfire',
  290. test: resolve('src/views/oneKeyOutfire'), // can customize your rules
  291. priority: 0,
  292. minSize: 0,
  293. minChunks: 1,
  294. enforce:true,
  295. reuseExistingChunk: true
  296. },
  297. safetyEducationExam: {
  298. name: 'chunk-safetyEducationExam',
  299. test: resolve('src/views/safetyEducationExam'), // can customize your rules
  300. priority: 0,
  301. minSize: 0,
  302. minChunks: 1,
  303. enforce:true,
  304. reuseExistingChunk: true
  305. },
  306. secureAccess: {
  307. name: 'chunk-secureAccess',
  308. test: resolve('src/views/secureAccess'), // can customize your rules
  309. priority: 0,
  310. minSize: 0,
  311. minChunks: 1,
  312. enforce:true,
  313. reuseExistingChunk: true
  314. },
  315. securityCheck: {
  316. name: 'chunk-securityCheck',
  317. test: resolve('src/views/securityCheck'), // can customize your rules
  318. priority: 0,
  319. minSize: 0,
  320. minChunks: 1,
  321. enforce:true,
  322. reuseExistingChunk: true
  323. },
  324. studentViews: {
  325. name: 'chunk-studentViews',
  326. test: resolve('src/views/studentViews'), // can customize your rules
  327. priority: 0,
  328. minSize: 0,
  329. minChunks: 1,
  330. enforce:true,
  331. reuseExistingChunk: true
  332. },
  333. system: {
  334. name: 'chunk-system',
  335. test: resolve('src/views/system'), // can customize your rules
  336. priority: 0,
  337. minSize: 0,
  338. minChunks: 1,
  339. enforce:true,
  340. reuseExistingChunk: true
  341. },
  342. }
  343. })
  344. config.optimization.runtimeChunk('single'),
  345. {
  346. from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件
  347. to: './', //到根目录下
  348. }
  349. }
  350. )
  351. }
  352. }