vue.config.js 14 KB

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