vue.config.js 13 KB

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