vue.config.js 13 KB

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