vue.config.js 14 KB

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