dedsudiyu 1 rok pred
rodič
commit
3fb9fe84ba
2 zmenil súbory, kde vykonal 37 pridanie a 1 odobranie
  1. 3 0
      public/index.html
  2. 34 1
      vue.config.js

+ 3 - 0
public/index.html

@@ -7,6 +7,9 @@
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
     <link rel="icon" href="<%= BASE_URL %>favicon.ico">
     <title><%= webpackConfig.name %></title>
+    <!-- <%= htmlWebpackPlugin.options.buildUser %> -->
+    <!-- <%= htmlWebpackPlugin.options.buildTime %> -->
+    <!-- <%= htmlWebpackPlugin.options.buildEdition %> -->
     <!--[if lt IE 11]><script>window.location.href='/html/ie.html';</script><![endif]-->
 	  <style>
     html,

+ 34 - 1
vue.config.js

@@ -1,6 +1,32 @@
 'use strict'
 const path = require('path')
 
+const ip = '192.168.1.43'
+const os = require('os')
+const fs = require("fs")
+//判断环境
+let ifaces = os.networkInterfaces()
+let localityIp = '', result = []
+for(let dev in ifaces) {
+  ifaces[dev].forEach(function(details) {
+    if(localityIp === '' && details.family === 'IPv4' && !details.internal) {
+      localityIp = details.address
+      return;
+    }
+  })
+}
+let getFile = localityIp == ip?false:true
+/******** 获取git版本信息 ********/
+const gitHEAD = getFile ? fs.readFileSync('.git/HEAD', 'utf-8').trim() : false
+const ref = getFile ? gitHEAD.split(': ')[1] : false
+const develop = getFile ? gitHEAD.split('/')[2] : false
+const gitVersion = getFile ? fs.readFileSync('.git/' + ref, 'utf-8').trim() : false
+const buildEdition = develop && gitVersion ? develop + ': ' + gitVersion : '未配置'
+const myDate = new Date()
+const buildTime = myDate.getFullYear() +'-'+ (myDate.getMonth()+1) +'-'+ myDate.getDate() +' '+ myDate.getHours() +':'+ myDate.getMinutes();
+const logsList = getFile ? fs.readFileSync('.git/logs/HEAD', 'utf-8').replace(/\r\n|\r/g, "\n").split("\n") : false
+const buildUser = getFile ? logsList[logsList.length-2].split(" ")[2] : '未配置'
+
 function resolve(dir) {
   return path.join(__dirname, dir)
 }
@@ -77,7 +103,14 @@ module.exports = {
     //   .loader('url-loader')
     //   .options({name:"img/[name].[hash:8].[ext]",limit: 1})
 
-
+    //标记打包时间与当前git版本信息
+    config.plugin('html').tap(args => {
+      args[0].buildUser = buildUser;
+      args[0].buildTime = buildTime;
+      args[0].buildEdition = buildEdition;
+      args[0].minify.removeComments = false
+      return args
+    })
     // set svg-sprite-loader
     config.module
       .rule('svg')