vue.config.js 13 KB

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