vue.config.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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. medicUniversity_3_1: {
  228. name: 'chunk-medicUniversity-3_1',
  229. test: resolve('src/views/medicUniversity-3_1'),
  230. priority: 0,
  231. minSize: 0,
  232. minChunks: 1,
  233. enforce:true,
  234. reuseExistingChunk: true
  235. },
  236. mine: {
  237. name: 'chunk-mine',
  238. test: resolve('src/views/mine'),
  239. priority: 0,
  240. minSize: 0,
  241. minChunks: 1,
  242. enforce:true,
  243. reuseExistingChunk: true
  244. },
  245. oneKeyOutfire: {
  246. name: 'chunk-oneKeyOutfire',
  247. test: resolve('src/views/oneKeyOutfire'),
  248. priority: 0,
  249. minSize: 0,
  250. minChunks: 1,
  251. enforce:true,
  252. reuseExistingChunk: true
  253. },
  254. studentViews: {
  255. name: 'chunk-studentViews',
  256. test: resolve('src/views/studentViews'),
  257. priority: 0,
  258. minSize: 0,
  259. minChunks: 1,
  260. enforce:true,
  261. reuseExistingChunk: true
  262. },
  263. system: {
  264. name: 'chunk-system',
  265. test: resolve('src/views/system'),
  266. priority: 0,
  267. minSize: 0,
  268. minChunks: 1,
  269. enforce:true,
  270. reuseExistingChunk: true
  271. },
  272. safetyCheck: {
  273. name: 'chunk-safetyCheck',
  274. test: resolve('src/views/safetyCheck'),
  275. priority: 0,
  276. minSize: 0,
  277. minChunks: 1,
  278. enforce:true,
  279. reuseExistingChunk: true
  280. },
  281. /************新优化************/
  282. //基础模块
  283. basicsModules: {
  284. name: 'chunk-basicsModules',
  285. test: resolve('src/views/basicsModules'),
  286. priority: 0,
  287. minSize: 0,
  288. minChunks: 1,
  289. enforce:true,
  290. reuseExistingChunk: true
  291. },
  292. //危险源管理
  293. hazardManagement: {
  294. name: 'chunk-hazardManagement',
  295. test: resolve('src/views/hazardManagement'),
  296. priority: 0,
  297. minSize: 0,
  298. minChunks: 1,
  299. enforce:true,
  300. reuseExistingChunk: true
  301. },
  302. //信用管理
  303. creditViolation: {
  304. name: 'chunk-creditViolation',
  305. test: resolve('src/views/creditViolation'),
  306. priority: 0,
  307. minSize: 0,
  308. minChunks: 1,
  309. enforce:true,
  310. reuseExistingChunk: true
  311. },
  312. //安全准入
  313. secureAccess: {
  314. name: 'chunk-secureAccess',
  315. test: resolve('src/views/secureAccess'),
  316. priority: 0,
  317. minSize: 0,
  318. minChunks: 1,
  319. enforce:true,
  320. reuseExistingChunk: true
  321. },
  322. //分级管控
  323. hierarchicalControl: {
  324. name: 'chunk-hierarchicalControl',
  325. test: resolve('src/views/hierarchicalControl'),
  326. priority: 0,
  327. minSize: 0,
  328. minChunks: 1,
  329. enforce:true,
  330. reuseExistingChunk: true
  331. },
  332. //气瓶管理-简化版
  333. gasManage_syd: {
  334. name: 'chunk-gasManage_syd',
  335. test: resolve('src/views/gasManage_syd'),
  336. priority: 0,
  337. minSize: 0,
  338. minChunks: 1,
  339. enforce:true,
  340. reuseExistingChunk: true
  341. },
  342. //气瓶管理-完全版
  343. gasManage3_0: {
  344. name: 'chunk-gasManage3_0',
  345. test: resolve('src/views/gasManage3_0'),
  346. priority: 0,
  347. minSize: 0,
  348. minChunks: 1,
  349. enforce:true,
  350. reuseExistingChunk: true
  351. },
  352. //安全检查(旧)
  353. securityCheck: {
  354. name: 'chunk-securityCheck',
  355. test: resolve('src/views/securityCheck'),
  356. priority: 0,
  357. minSize: 0,
  358. minChunks: 1,
  359. enforce:true,
  360. reuseExistingChunk: true
  361. },
  362. //安全教育与考试
  363. safetyEducationExam: {
  364. name: 'chunk-safetyEducationExam',
  365. test: resolve('src/views/safetyEducationExam'),
  366. priority: 0,
  367. minSize: 0,
  368. minChunks: 1,
  369. enforce:true,
  370. reuseExistingChunk: true
  371. },
  372. //服务中心
  373. serviceCenter: {
  374. name: 'chunk-serviceCenter',
  375. test: resolve('src/views/serviceCenter'),
  376. priority: 0,
  377. minSize: 0,
  378. minChunks: 1,
  379. enforce:true,
  380. reuseExistingChunk: true
  381. },
  382. //系统管理
  383. systemManagement: {
  384. name: 'chunk-systemManagement',
  385. test: resolve('src/views/systemManagement'),
  386. priority: 0,
  387. minSize: 0,
  388. minChunks: 1,
  389. enforce:true,
  390. reuseExistingChunk: true
  391. },
  392. //综合管理
  393. integratedManagement: {
  394. name: 'chunk-integratedManagement',
  395. test: resolve('src/views/integratedManagement'),
  396. priority: 0,
  397. minSize: 0,
  398. minChunks: 1,
  399. enforce:true,
  400. reuseExistingChunk: true
  401. },
  402. //物联设备
  403. iotDevice: {
  404. name: 'chunk-iotDevice',
  405. test: resolve('src/views/iotDevice'),
  406. priority: 0,
  407. minSize: 0,
  408. minChunks: 1,
  409. enforce:true,
  410. reuseExistingChunk: true
  411. },
  412. //应急预警
  413. emergencyManagement: {
  414. name: 'chunk-emergencyManagement',
  415. test: resolve('src/views/emergencyManagement'),
  416. priority: 0,
  417. minSize: 0,
  418. minChunks: 1,
  419. enforce:true,
  420. reuseExistingChunk: true
  421. },
  422. //化学品管理
  423. chemicalManage: {
  424. name: 'chunk-chemicalManage',
  425. test: resolve('src/views/chemicalManage'),
  426. priority: 0,
  427. minSize: 0,
  428. minChunks: 1,
  429. enforce:true,
  430. reuseExistingChunk: true
  431. },
  432. }
  433. })
  434. config.optimization.runtimeChunk('single'),{
  435. from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件
  436. to: './', //到根目录下
  437. }
  438. }
  439. }