Explorar o código

增加构建优化

Michael Wang %!s(int64=6) %!d(string=hai) anos
pai
achega
b7c384dbd0
Modificáronse 5 ficheiros con 66 adicións e 0 borrados
  1. 0 0
      .env.development
  2. 1 0
      .env.production
  3. 8 0
      jsconfig.json
  4. 25 0
      postbuild.js
  5. 32 0
      prebuild.js

+ 0 - 0
.env.development


+ 1 - 0
.env.production

@@ -0,0 +1 @@
+VUE_APP_GIT_REPO_VERSION=TO_BE_OVERRIDED

+ 8 - 0
jsconfig.json

@@ -0,0 +1,8 @@
+{
+  "compilerOptions": {
+    "baseUrl": ".",
+    "paths": {
+      "@/*": ["./src/*"]
+    }
+  }
+}

+ 25 - 0
postbuild.js

@@ -0,0 +1,25 @@
+console.log("> postbuild");
+console.log("> postbuild 将sourcemap文件改名,防止源码泄露");
+
+const revision = require("child_process")
+  .execSync("git rev-parse HEAD")
+  .toString()
+  .trim()
+  .slice(10, 17);
+const fs = require("fs");
+const DIR = "./dist/js/";
+const sourcemaps = fs
+  .readdirSync(DIR)
+  .filter(v => v.endsWith(".map"))
+  .map(v => DIR + v);
+for (const s of sourcemaps) {
+  fs.renameSync(s, s.replace(".js.map", "-" + revision + ".js.map"));
+  console.log(
+    "  rename ",
+    s,
+    " => ",
+    s.replace(".js.map", "-" + revision + ".js.map")
+  );
+}
+
+console.log();

+ 32 - 0
prebuild.js

@@ -0,0 +1,32 @@
+const packageJson = require("./package.json");
+
+if (packageJson.dependencies.iview !== "^3.4.1") {
+  console.log("iview 的版本不要轻易升级,一定要充分测试。");
+  process.exit(1);
+}
+
+console.log("> prebuild");
+console.log("> prebuild create .env.production.local");
+
+const buildDate = require("moment")().format("YYYY-MM-DD HH:mm:SS");
+console.log("  构建日期为 " + buildDate);
+
+const revision = require("child_process")
+  .execSync("git rev-parse HEAD")
+  .toString()
+  .trim()
+  .slice(0, 7);
+const fs = require("fs");
+console.log("  当前的git版本为 " + revision);
+
+fs.writeFileSync(
+  ".env.production.local",
+  "VUE_APP_GIT_REPO_VERSION=" + buildDate + " - " + revision
+);
+
+fs.writeFileSync(
+  ".env.staging.local",
+  "VUE_APP_GIT_REPO_VERSION=" + buildDate + " - " + revision
+);
+
+console.log();