瀏覽代碼

添加配置信息

zhangyu 4 年之前
父節點
當前提交
531b66cc3a
共有 7 個文件被更改,包括 143 次插入31 次删除
  1. 2 0
      .env.aly
  2. 2 0
      .env.production
  3. 8 4
      package.json
  4. 1 1
      publish.js
  5. 26 21
      src/router/index.ts
  6. 55 0
      version.js
  7. 49 5
      vue.config.js

+ 2 - 0
.env.aly

@@ -0,0 +1,2 @@
+NODE_ENV=production
+VUE_Plan_RealEnv=aly

+ 2 - 0
.env.production

@@ -0,0 +1,2 @@
+NODE_ENV=production
+VUE_Plan_RealEnv=production

+ 8 - 4
package.json

@@ -10,9 +10,11 @@
   },
   "scripts": {
     "serve": "vue-cli-service serve",
-    "build": "vue-cli-service build",
+    "build_aly": "vue-cli-service build --mode aly",
+    "build_prod": "vue-cli-service build --mode production",
     "lint": "vue-cli-service lint",
-    "publish": "node publish.js"
+    "publish": "node publish.js",
+    "version": "node version.js"
   },
   "dependencies": {
     "@persagy-web/base": "2.2.1",
@@ -33,7 +35,8 @@
     "vue-class-component": "^7.2.3",
     "vue-property-decorator": "^8.4.2",
     "vue-router": "^3.2.0",
-    "vuex": "^3.4.0"
+    "vuex": "^3.4.0",
+    "compression-webpack-plugin": "^5.0.2"
   },
   "devDependencies": {
     "@typescript-eslint/eslint-plugin": "^2.33.0",
@@ -56,6 +59,7 @@
     "svgo": "^1.3.2",
     "svgo-loader": "^2.2.1",
     "typescript": "~3.9.3",
-    "vue-template-compiler": "^2.6.11"
+    "vue-template-compiler": "^2.6.11",
+    "webpack-bundle-analyzer": "^3.8.0"
   }
 }

+ 1 - 1
publish.js

@@ -25,7 +25,7 @@
  * *********************************************************************************************************************
  */
 
-const Client = require("node-ssh");
+import Client from "node-ssh";
 const ssh = new Client();
 
 ssh.connect({

+ 26 - 21
src/router/index.ts

@@ -1,25 +1,30 @@
-import Vue from 'vue'
-import VueRouter, { RouteConfig } from 'vue-router'
-const Editer = () => import('../views/editer.vue')
-const Home = () => import('../views/home.vue')
-Vue.use(VueRouter)
+import Vue from "vue";
+import VueRouter, { RouteConfig } from "vue-router";
+const Editer = () => import("../views/editer.vue");
+const Home = () => import("../views/home.vue");
+Vue.use(VueRouter);
 const routes: Array<RouteConfig> = [
-  {
-    path: '/editer',
-    name: 'Editer',
-    component: Editer
-  },
-  {
-    path: '/home',
-    name: 'home',
-    component: Home
-  }
-]
+    {
+        path: "/",
+        name: "index",
+        component: Home,
+    },
+    {
+        path: "/editer",
+        name: "Editer",
+        component: Editer,
+    },
+    {
+        path: "/home",
+        name: "home",
+        component: Home,
+    },
+];
 
 const router = new VueRouter({
-  mode: 'history',
-  base: "persagyPlan",
-  routes
-})
+    mode: "history",
+    base: "persagyPlan",
+    routes,
+});
 
-export default router
+export default router;

+ 55 - 0
version.js

@@ -0,0 +1,55 @@
+/** 自动记录版本信息**/
+import { writeFile } from 'fs'
+const buildPath = process.env.npm_package_remote_local //放置 version.txt的路径
+import { execSync } from 'child_process' //同步子进程
+const date = new Date() // Date对象
+
+// 获取时间函数
+const getDate = (df, tf) => {
+    const dArr = [
+        date.getFullYear(),
+        date.getMonth() > 9 ? String(date.getMonth() + 1) : String('0' + (date.getMonth() + 1)),
+        date.getDate() > 9 ? String(date.getDate()) : String('0' + date.getDate()),
+    ]
+    const tArr = [date.getHours(), date.getMinutes() > 9 ? String(date.getMinutes() + 1) : String('0' + date.getMinutes())]
+    return `${dArr.join(df)}${tf ? ' ' : ''}${tArr.join(tf)}`
+}
+//写入最新的版本信息
+const branch = execSync('git symbolic-ref --short -q HEAD')
+    .toString()
+    .trim() // 分支
+const commit = execSync('git show -s --format=%h')
+    .toString()
+    .trim() //版本号
+const message = execSync('git show -s --format=%s')
+    .toString()
+    .trim() //说明
+const name = execSync('git show -s --format=%cn')
+    .toString()
+    .trim() //姓名
+const email = execSync('git show -s --format=%ce')
+    .toString()
+    .trim() //邮箱
+//const date = execSync('git show -s --format=%cd').toString().trim(); //日期
+const versionStr = `git:${commit}<${branch}>\n作者:${name}<${email}>\n日期:${getDate('-', ':')}\n说明:${message}\n`
+writeFile(`${buildPath}/version.txt`, versionStr, (err) => {
+    if (err) console.err('写入失败', err)
+})
+
+// 打包文件命名
+const distName = `打包命名:${buildPath}_${getDate('', '')}_git_${commit}`
+
+// 程序运行结束
+console.info(
+    '\x1B[32m%s\x1b[0m',
+    [
+        distName,
+        versionStr,
+        '██████╗ ███████╗██████╗ ███████╗ █████╗  ██████╗██╗   ██╗',
+        '██╔══██╗██╔════╝██╔══██╗██╔════╝██╔══██╗██╔════╝╚██╗ ██╔╝',
+        '██████╔╝█████╗  ██████╔╝███████╗███████║██║  ███╗╚████╔╝ ',
+        '██╔═══╝ ██╔══╝  ██╔══██╗╚════██║██╔══██║██║   ██║ ╚██╔╝  ',
+        '██║     ███████╗██║  ██║███████║██║  ██║╚██████╔╝  ██║   ',
+        '╚═╝     ╚══════╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝ ╚═════╝   ╚═╝   ',
+    ].join('\n')
+)

+ 49 - 5
vue.config.js

@@ -1,10 +1,13 @@
+/* eslint-disable @typescript-eslint/camelcase */
+// gzip 压缩代码
+const CompressionPlugin = require('compression-webpack-plugin')
+// 打包分析
+const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
+// terser-webpack-plugin 可不引入, @vue/cli-service 中已经引入了terser-webpack-plugin
+// const TerserPlugin = require('terser-webpack-plugin')
 module.exports = {
     devServer: {
-        // 关闭esline
-        overlay: {
-            warnings: false,
-            errors: false,
-        },
+        open: true,
         proxy: {
             '/labsl': {
                 target: 'http://60.205.177.43:8080',
@@ -33,6 +36,15 @@ module.exports = {
                 secure: false,
             },
         },
+        // 关闭esline
+        overlay: {
+            warnings: false,
+            errors: false,
+        },
+    },
+    chainWebpack: (config) => {
+        config.output.filename('static/js/[name].[hash].js').end()
+        config.output.chunkFilename('static/js/[name].[hash].js').end()
     },
     lintOnSave: false,
     publicPath: '/persagyPlan',
@@ -40,6 +52,38 @@ module.exports = {
     outputDir: 'persagyPlan',
     // 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录
     assetsDir: 'static',
+    transpileDependencies: [
+        '@persagy-web', // 指定对第三方依赖包进行babel-polyfill处理
+    ],
+    // CSS 相关选项
+    css: {
+        // 将组件内的 CSS 提取到一个单独的 CSS 文件 (只用在生产环境中)
+        extract: true,
+    },
+    // 配置webpack
+    configureWebpack: (config) => {
+        // 生成环境,删除console.log和debugger
+        if (process.env.VUE_Plan_RealEnv === 'production') {
+            config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true //删除console
+            config.optimization.minimizer[0].options.terserOptions.compress.drop_debugger = true //删除 debugger
+            config.optimization.minimizer[0].options.terserOptions.compress.pure_funcs = ['console.log'] //删除
+        }
+        const plugins = [
+            // 压缩代码
+            new CompressionPlugin({
+                test: /\.js$|\.html$|\.css$/, // 匹配文件名
+                threshold: 10240, // 对超过10k的数据压缩
+                deleteOriginalAssets: true, // false 不删除源文件 true 删除源文件
+            }),
+        ]
+        // 生产环境打包分析体积 命令 npm run  build --report 或者 yarn build --report
+        if (process.env.NODE_ENV === 'production' && (process.env.npm_config_report || process.env.npm_config_argv.indexOf('--report') !== -1)) {
+            plugins.push(new BundleAnalyzerPlugin())
+        }
+        return {
+            plugins,
+        }
+    },
     // chainWebpack:config =>{
     //     config.module.rule('svg-sprite')
     //     .use('svgo-loader')