vue.config.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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. transpileDependencies: ['@zumer/snapdom'],
  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. basicsModules: {
  224. name: 'chunk-basicsModules',
  225. test: resolve('src/views/basicsModules'),
  226. priority: 0,
  227. minSize: 0,
  228. minChunks: 1,
  229. enforce:true,
  230. reuseExistingChunk: true
  231. },
  232. chemicalManage: {
  233. name: 'chunk-chemicalManage',
  234. test: resolve('src/views/chemicalManage'),
  235. priority: 0,
  236. minSize: 0,
  237. minChunks: 1,
  238. enforce:true,
  239. reuseExistingChunk: true
  240. },
  241. creditViolation: {
  242. name: 'chunk-creditViolation',
  243. test: resolve('src/views/creditViolation'),
  244. priority: 0,
  245. minSize: 0,
  246. minChunks: 1,
  247. enforce:true,
  248. reuseExistingChunk: true
  249. },
  250. emergencyManagement: {
  251. name: 'chunk-emergencyManagement',
  252. test: resolve('src/views/emergencyManagement'),
  253. priority: 0,
  254. minSize: 0,
  255. minChunks: 1,
  256. enforce:true,
  257. reuseExistingChunk: true
  258. },
  259. gasManage3_0: {
  260. name: 'chunk-gasManage3_0',
  261. test: resolve('src/views/gasManage3_0'),
  262. priority: 0,
  263. minSize: 0,
  264. minChunks: 1,
  265. enforce:true,
  266. reuseExistingChunk: true
  267. },
  268. gasManage_syd: {
  269. name: 'chunk-gasManage_syd',
  270. test: resolve('src/views/gasManage_syd'),
  271. priority: 0,
  272. minSize: 0,
  273. minChunks: 1,
  274. enforce:true,
  275. reuseExistingChunk: true
  276. },
  277. hierarchicalControl: {
  278. name: 'chunk-hierarchicalControl',
  279. test: resolve('src/views/hierarchicalControl'),
  280. priority: 0,
  281. minSize: 0,
  282. minChunks: 1,
  283. enforce:true,
  284. reuseExistingChunk: true
  285. },
  286. //基础模块
  287. integratedManagement: {
  288. name: 'chunk-integratedManagement',
  289. test: resolve('src/views/integratedManagement'),
  290. priority: 0,
  291. minSize: 0,
  292. minChunks: 1,
  293. enforce:true,
  294. reuseExistingChunk: true
  295. },
  296. //信用管理
  297. iotDevice: {
  298. name: 'chunk-iotDevice',
  299. test: resolve('src/views/iotDevice'),
  300. priority: 0,
  301. minSize: 0,
  302. minChunks: 1,
  303. enforce:true,
  304. reuseExistingChunk: true
  305. },
  306. //安全准入
  307. safetyCheck: {
  308. name: 'chunk-safetyCheck',
  309. test: resolve('src/views/safetyCheck'),
  310. priority: 0,
  311. minSize: 0,
  312. minChunks: 1,
  313. enforce:true,
  314. reuseExistingChunk: true
  315. },
  316. //分级管控
  317. safetyEducationExam: {
  318. name: 'chunk-safetyEducationExam',
  319. test: resolve('src/views/safetyEducationExam'),
  320. priority: 0,
  321. minSize: 0,
  322. minChunks: 1,
  323. enforce:true,
  324. reuseExistingChunk: true
  325. },
  326. //气瓶管理-简化版
  327. secureAccess: {
  328. name: 'chunk-secureAccess',
  329. test: resolve('src/views/secureAccess'),
  330. priority: 0,
  331. minSize: 0,
  332. minChunks: 1,
  333. enforce:true,
  334. reuseExistingChunk: true
  335. },
  336. //气瓶管理-完全版
  337. securityCheck: {
  338. name: 'chunk-securityCheck',
  339. test: resolve('src/views/securityCheck'),
  340. priority: 0,
  341. minSize: 0,
  342. minChunks: 1,
  343. enforce:true,
  344. reuseExistingChunk: true
  345. },
  346. //安全检查(旧)
  347. serviceCenter: {
  348. name: 'chunk-serviceCenter',
  349. test: resolve('src/views/serviceCenter'),
  350. priority: 0,
  351. minSize: 0,
  352. minChunks: 1,
  353. enforce:true,
  354. reuseExistingChunk: true
  355. },
  356. //安全教育与考试
  357. systemManagement: {
  358. name: 'chunk-systemManagement',
  359. test: resolve('src/views/systemManagement'),
  360. priority: 0,
  361. minSize: 0,
  362. minChunks: 1,
  363. enforce:true,
  364. reuseExistingChunk: true
  365. },
  366. //危废回收
  367. hazardousWasteRecycling: {
  368. name: 'chunk-hazardousWasteRecycling',
  369. test: resolve('src/views/hazardousWasteRecycling'),
  370. priority: 0,
  371. minSize: 0,
  372. minChunks: 1,
  373. enforce:true,
  374. reuseExistingChunk: true
  375. },
  376. }
  377. })
  378. config.optimization.runtimeChunk('single'),{
  379. from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件
  380. to: './', //到根目录下
  381. }
  382. }
  383. }