mirror of
https://github.com/cool-team-official/cool-admin-vue.git
synced 2024-11-01 14:10:27 +08:00
解决 vite-plugin 重新刷新问题
This commit is contained in:
parent
d17e1a960b
commit
d5e918c0fc
1
packages/vite-plugin/dist/eps/index.d.ts
vendored
1
packages/vite-plugin/dist/eps/index.d.ts
vendored
@ -4,4 +4,5 @@ export declare function createEps(query?: {
|
||||
}): Promise<{
|
||||
service: {};
|
||||
list: Eps.Entity[];
|
||||
isUpdate: boolean;
|
||||
}>;
|
||||
|
53
packages/vite-plugin/dist/index.js
vendored
53
packages/vite-plugin/dist/index.js
vendored
@ -192,7 +192,7 @@
|
||||
}
|
||||
// 创建 json 文件
|
||||
function createJson() {
|
||||
const d = list.map((e) => {
|
||||
const arr = list.map((e) => {
|
||||
return {
|
||||
prefix: e.prefix,
|
||||
name: e.name || "",
|
||||
@ -205,9 +205,16 @@
|
||||
}),
|
||||
};
|
||||
});
|
||||
fs.createWriteStream(getEpsPath("eps.json"), {
|
||||
flags: "w",
|
||||
}).write(JSON.stringify(d));
|
||||
const content = JSON.stringify(arr);
|
||||
const local_content = readFile(getEpsPath("eps.json"));
|
||||
// 是否需要更新
|
||||
const isUpdate = content != local_content;
|
||||
if (isUpdate) {
|
||||
fs.createWriteStream(getEpsPath("eps.json"), {
|
||||
flags: "w",
|
||||
}).write(content);
|
||||
}
|
||||
return isUpdate;
|
||||
}
|
||||
// 创建描述文件
|
||||
async function createDescribe({ list, service }) {
|
||||
@ -411,10 +418,14 @@
|
||||
printWidth: 100,
|
||||
trailingComma: "none",
|
||||
});
|
||||
// 创建 eps 描述文件
|
||||
fs.createWriteStream(getEpsPath("eps.d.ts"), {
|
||||
flags: "w",
|
||||
}).write(content);
|
||||
const local_content = readFile(getEpsPath("eps.d.ts"));
|
||||
// 是否需要更新
|
||||
if (content != local_content) {
|
||||
// 创建 eps 描述文件
|
||||
fs.createWriteStream(getEpsPath("eps.d.ts"), {
|
||||
flags: "w",
|
||||
}).write(content);
|
||||
}
|
||||
}
|
||||
// 创建 service
|
||||
function createService() {
|
||||
@ -473,12 +484,13 @@
|
||||
// 创建目录
|
||||
createDir(getEpsPath(), true);
|
||||
// 创建 json 文件
|
||||
createJson();
|
||||
const isUpdate = createJson();
|
||||
// 创建描述文件
|
||||
createDescribe({ service, list });
|
||||
return {
|
||||
service,
|
||||
list,
|
||||
isUpdate,
|
||||
};
|
||||
}
|
||||
|
||||
@ -707,8 +719,15 @@
|
||||
});
|
||||
}
|
||||
}
|
||||
// 排序后检测,避免加载顺序问题
|
||||
function order(d) {
|
||||
return {
|
||||
pages: lodash.orderBy(d.pages, "path"),
|
||||
subPackages: lodash.orderBy(d.subPackages, "root"),
|
||||
};
|
||||
}
|
||||
// 是否需要更新 pages.json
|
||||
if (!lodash.isEqual(ctxData, ctx)) {
|
||||
if (!lodash.isEqual(order(ctxData), order(ctx))) {
|
||||
console.log("[cool-ctx] pages updated");
|
||||
writeFile(ctxPath, JSON.stringify(ctx, null, 4));
|
||||
}
|
||||
@ -747,12 +766,14 @@
|
||||
if (!["pages.json", "dist", "build/cool", "eps.json", "eps.d.ts"].some((e) => file.includes(e))) {
|
||||
createCtx();
|
||||
createEps().then((data) => {
|
||||
// 通知客户端刷新
|
||||
(server.hot || server.ws).send({
|
||||
type: "custom",
|
||||
event: "eps-update",
|
||||
data,
|
||||
});
|
||||
if (data.isUpdate) {
|
||||
// 通知客户端刷新
|
||||
(server.hot || server.ws).send({
|
||||
type: "custom",
|
||||
event: "eps-update",
|
||||
data,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@cool-vue/vite-plugin",
|
||||
"version": "7.1.2",
|
||||
"version": "7.1.3",
|
||||
"description": "cool-admin/cool-uni builder",
|
||||
"main": "/dist/index.js",
|
||||
"scripts": {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { join } from "path";
|
||||
import { readFile, rootDir, writeFile } from "../utils";
|
||||
import { glob } from "glob";
|
||||
import { assign, cloneDeep, isEqual } from "lodash";
|
||||
import { assign, cloneDeep, isEqual, orderBy } from "lodash";
|
||||
import type { Ctx } from "../../types";
|
||||
import { config } from "../config";
|
||||
import fs from "fs";
|
||||
@ -61,8 +61,16 @@ export async function createCtx() {
|
||||
}
|
||||
}
|
||||
|
||||
// 排序后检测,避免加载顺序问题
|
||||
function order(d: Ctx.Data) {
|
||||
return {
|
||||
pages: orderBy(d.pages, "path"),
|
||||
subPackages: orderBy(d.subPackages, "root"),
|
||||
};
|
||||
}
|
||||
|
||||
// 是否需要更新 pages.json
|
||||
if (!isEqual(ctxData, ctx)) {
|
||||
if (!isEqual(order(ctxData), order(ctx))) {
|
||||
console.log("[cool-ctx] pages updated");
|
||||
writeFile(ctxPath, JSON.stringify(ctx, null, 4));
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ async function getData(data?: Eps.Entity[]) {
|
||||
|
||||
// 创建 json 文件
|
||||
function createJson() {
|
||||
const d = list.map((e) => {
|
||||
const arr = list.map((e) => {
|
||||
return {
|
||||
prefix: e.prefix,
|
||||
name: e.name || "",
|
||||
@ -119,9 +119,19 @@ function createJson() {
|
||||
};
|
||||
});
|
||||
|
||||
createWriteStream(getEpsPath("eps.json"), {
|
||||
flags: "w",
|
||||
}).write(JSON.stringify(d));
|
||||
const content = JSON.stringify(arr);
|
||||
const local_content = readFile(getEpsPath("eps.json"));
|
||||
|
||||
// 是否需要更新
|
||||
const isUpdate = content != local_content;
|
||||
|
||||
if (isUpdate) {
|
||||
createWriteStream(getEpsPath("eps.json"), {
|
||||
flags: "w",
|
||||
}).write(content);
|
||||
}
|
||||
|
||||
return isUpdate;
|
||||
}
|
||||
|
||||
// 创建描述文件
|
||||
@ -372,10 +382,15 @@ async function createDescribe({ list, service }: { list: Eps.Entity[]; service:
|
||||
trailingComma: "none",
|
||||
});
|
||||
|
||||
// 创建 eps 描述文件
|
||||
createWriteStream(getEpsPath("eps.d.ts"), {
|
||||
flags: "w",
|
||||
}).write(content);
|
||||
const local_content = readFile(getEpsPath("eps.d.ts"));
|
||||
|
||||
// 是否需要更新
|
||||
if (content != local_content) {
|
||||
// 创建 eps 描述文件
|
||||
createWriteStream(getEpsPath("eps.d.ts"), {
|
||||
flags: "w",
|
||||
}).write(content);
|
||||
}
|
||||
}
|
||||
|
||||
// 创建 service
|
||||
@ -448,7 +463,7 @@ export async function createEps(query?: { list: any[] }) {
|
||||
createDir(getEpsPath(), true);
|
||||
|
||||
// 创建 json 文件
|
||||
createJson();
|
||||
const isUpdate = createJson();
|
||||
|
||||
// 创建描述文件
|
||||
createDescribe({ service, list });
|
||||
@ -456,5 +471,6 @@ export async function createEps(query?: { list: any[] }) {
|
||||
return {
|
||||
service,
|
||||
list,
|
||||
isUpdate,
|
||||
};
|
||||
}
|
||||
|
@ -33,14 +33,15 @@ export async function virtual(): Promise<Plugin> {
|
||||
)
|
||||
) {
|
||||
createCtx();
|
||||
|
||||
createEps().then((data) => {
|
||||
// 通知客户端刷新
|
||||
(server.hot || server.ws).send({
|
||||
type: "custom",
|
||||
event: "eps-update",
|
||||
data,
|
||||
});
|
||||
if (data.isUpdate) {
|
||||
// 通知客户端刷新
|
||||
(server.hot || server.ws).send({
|
||||
type: "custom",
|
||||
event: "eps-update",
|
||||
data,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user