vue.config.js 12 KB

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