feat: dynamic publicPath

This commit is contained in:
jimqing 2021-02-28 16:57:58 +08:00
parent 070902093a
commit 6698d0cdda
3 changed files with 14 additions and 22 deletions

11
manifest.js Normal file
View File

@ -0,0 +1,11 @@
const fs = require("fs");
const manifest = require("./src/manifest.json");
manifest.h5.publicPath = process.env.SERVER_ENV !== "NETLIFY" ? "/md/" : "/";
const result = JSON.stringify(manifest, null, 2);
fs.writeFile("./src/manifest.json", result, function (err) {
if (err) {
console.error(err);
}
});

View File

@ -3,12 +3,12 @@
"version": "1.5.0",
"private": true,
"scripts": {
"serve": "npm run dev:h5",
"build": "npm run build:h5",
"serve": "node manifest.js & npm run dev:h5",
"build": "node manifest.js & npm run build:h5",
"build:h5-netlify": "cross-env SERVER_ENV=NETLIFY node manifest.js & npm run build:h5",
"build:app-plus": "cross-env NODE_ENV=production UNI_PLATFORM=app-plus vue-cli-service uni-build",
"build:custom": "cross-env NODE_ENV=production uniapp-cli custom",
"build:h5": "cross-env NODE_ENV=production UNI_OUTPUT_DIR=dist UNI_PLATFORM=h5 vue-cli-service uni-build",
"build:h5-netlify": "cross-env NODE_ENV=production SERVER_ENV=NETLIFY UNI_OUTPUT_DIR=dist UNI_PLATFORM=h5 vue-cli-service uni-build",
"build:mp-360": "cross-env NODE_ENV=production UNI_PLATFORM=mp-360 vue-cli-service uni-build",
"build:mp-alipay": "cross-env NODE_ENV=production UNI_PLATFORM=mp-alipay vue-cli-service uni-build",
"build:mp-baidu": "cross-env NODE_ENV=production UNI_PLATFORM=mp-baidu vue-cli-service uni-build",

View File

@ -1,19 +0,0 @@
const fs = require("fs");
function writeManifestJson() {
fs.readFile("./src/manifest.json", function (err, data) {
if (err) {
return console.error(err);
}
const strData = data.toString();
const manifest = JSON.parse(strData);
manifest.h5.publicPath = process.env.SERVER_ENV !== "NETLIFY" ? "/md/" : "/";
const result = JSON.stringify(manifest, null, 2);
fs.writeFile("./src/manifest.json", result, function (err) {
if (err) {
console.error(err);
}
});
});
}