@pubinfo/vite 2.1.10-beta.1 → 2.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +117 -11
- package/package.json +28 -28
package/dist/index.mjs
CHANGED
|
@@ -13,6 +13,8 @@ import { createParsedCommandLine, createVueLanguagePlugin, getDefaultCompilerOpt
|
|
|
13
13
|
import ts from "typescript";
|
|
14
14
|
import boxen from "boxen";
|
|
15
15
|
import MagicString from "magic-string";
|
|
16
|
+
import { Buffer } from "node:buffer";
|
|
17
|
+
import { createHash } from "node:crypto";
|
|
16
18
|
import fg from "fast-glob";
|
|
17
19
|
import { merge } from "lodash-es";
|
|
18
20
|
import picomatch from "picomatch";
|
|
@@ -22,7 +24,6 @@ import dayjs from "dayjs";
|
|
|
22
24
|
import { readPackageJSON } from "pkg-types";
|
|
23
25
|
import { readFile } from "node:fs/promises";
|
|
24
26
|
import { fileURLToPath } from "node:url";
|
|
25
|
-
import { Buffer } from "node:buffer";
|
|
26
27
|
import fse from "fs-extra/esm";
|
|
27
28
|
import JSZip from "jszip";
|
|
28
29
|
import autoImport from "unplugin-auto-import/vite";
|
|
@@ -72,7 +73,7 @@ function getServerProxy(env, isProxy) {
|
|
|
72
73
|
else serverProxy[pk] = {
|
|
73
74
|
target: url,
|
|
74
75
|
changeOrigin: true,
|
|
75
|
-
rewrite: (path
|
|
76
|
+
rewrite: (path) => path.replace(pk, ""),
|
|
76
77
|
secure: false
|
|
77
78
|
};
|
|
78
79
|
}
|
|
@@ -149,7 +150,7 @@ function createDTS(options = {}) {
|
|
|
149
150
|
console.error("[pubinfo:dts] Could not find tsconfig.json");
|
|
150
151
|
return;
|
|
151
152
|
}
|
|
152
|
-
const configFile = ts.readConfigFile(configPath, (path
|
|
153
|
+
const configFile = ts.readConfigFile(configPath, (path) => readFileSync(path, "utf-8"));
|
|
153
154
|
if (configFile.error) {
|
|
154
155
|
console.error("[pubinfo:dts] Error reading tsconfig.json");
|
|
155
156
|
return;
|
|
@@ -214,7 +215,7 @@ function createDTS(options = {}) {
|
|
|
214
215
|
return true;
|
|
215
216
|
});
|
|
216
217
|
if (diagnostics.length > 0) console.warn("[pubinfo:dts] Type diagnostics:\n", ts.formatDiagnosticsWithColorAndContext(diagnostics, {
|
|
217
|
-
getCanonicalFileName: (path
|
|
218
|
+
getCanonicalFileName: (path) => path,
|
|
218
219
|
getCurrentDirectory: () => root,
|
|
219
220
|
getNewLine: () => "\n"
|
|
220
221
|
}));
|
|
@@ -307,6 +308,59 @@ function createInjectAuto(options) {
|
|
|
307
308
|
};
|
|
308
309
|
}
|
|
309
310
|
|
|
311
|
+
//#endregion
|
|
312
|
+
//#region src/plugins/built-in/json-url-asset.ts
|
|
313
|
+
const BASE64_DATA_URL_RE = /["']data:application\/json;base64,([A-Za-z0-9+/=]+)["']/g;
|
|
314
|
+
/**
|
|
315
|
+
* 修复 Vite 8 + Rolldown 中 JSON 文件通过 `?url` 导入时
|
|
316
|
+
* 被内联为 base64 data URL 的问题。
|
|
317
|
+
*
|
|
318
|
+
* 问题原因:
|
|
319
|
+
* 1. 模块(如 rbac)作为 library 预构建时,`?url` 导入的 JSON 文件
|
|
320
|
+
* 被 Rolldown 直接转为 base64 data URL 内联到产物中,忽略 `assetsInlineLimit`。
|
|
321
|
+
* 2. 当主应用(playground)打包时消费这些预构建产物,base64 数据被原封不动保留。
|
|
322
|
+
*
|
|
323
|
+
* 解决方案:在 `transform` 钩子中检测已内联的 `data:application/json;base64,...`
|
|
324
|
+
* 字符串,将其解码并通过 `this.emitFile` 作为独立资源文件输出,
|
|
325
|
+
* 用 `import.meta.ROLLUP_FILE_URL_` 引用替换原始 data URL。
|
|
326
|
+
*/
|
|
327
|
+
function createJsonUrlAsset() {
|
|
328
|
+
let isBuild = false;
|
|
329
|
+
const emitted = /* @__PURE__ */ new Map();
|
|
330
|
+
return {
|
|
331
|
+
name: "pubinfo:json-url-asset",
|
|
332
|
+
enforce: "pre",
|
|
333
|
+
config(_config, env) {
|
|
334
|
+
isBuild = env.command === "build";
|
|
335
|
+
},
|
|
336
|
+
transform(code, _id) {
|
|
337
|
+
if (!isBuild) return null;
|
|
338
|
+
if (!code.includes("data:application/json;base64,")) return null;
|
|
339
|
+
let hasReplacement = false;
|
|
340
|
+
const result = code.replace(BASE64_DATA_URL_RE, (_match, base64Data) => {
|
|
341
|
+
const hash = createHash("sha256").update(base64Data).digest("hex").slice(0, 8);
|
|
342
|
+
let refId = emitted.get(hash);
|
|
343
|
+
if (!refId) {
|
|
344
|
+
const buffer = Buffer.from(base64Data, "base64");
|
|
345
|
+
refId = this.emitFile({
|
|
346
|
+
type: "asset",
|
|
347
|
+
name: `json-asset-${hash}.json`,
|
|
348
|
+
source: buffer
|
|
349
|
+
});
|
|
350
|
+
emitted.set(hash, refId);
|
|
351
|
+
}
|
|
352
|
+
hasReplacement = true;
|
|
353
|
+
return `import.meta.ROLLUP_FILE_URL_${refId}`;
|
|
354
|
+
});
|
|
355
|
+
if (hasReplacement) return {
|
|
356
|
+
code: result,
|
|
357
|
+
map: null
|
|
358
|
+
};
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
310
364
|
//#endregion
|
|
311
365
|
//#region src/plugins/built-in/lib-resolver.ts
|
|
312
366
|
function getPatternBase(pattern) {
|
|
@@ -318,8 +372,8 @@ function getPatternBase(pattern) {
|
|
|
318
372
|
}
|
|
319
373
|
return baseParts.join("/");
|
|
320
374
|
}
|
|
321
|
-
function normalizePath$1(path
|
|
322
|
-
return posix.normalize(path
|
|
375
|
+
function normalizePath$1(path) {
|
|
376
|
+
return posix.normalize(path.replace(/\\/g, "/"));
|
|
323
377
|
}
|
|
324
378
|
function libResolverPlugin(options) {
|
|
325
379
|
const virtualModuleId = "virtual:pubinfo-resolver";
|
|
@@ -726,6 +780,7 @@ function createUnocss() {
|
|
|
726
780
|
//#region src/plugins/index.ts
|
|
727
781
|
function createVitePlugins(viteEnv, isBuild = false, config, type) {
|
|
728
782
|
const vitePlugins = [
|
|
783
|
+
createJsonUrlAsset(),
|
|
729
784
|
vue(),
|
|
730
785
|
vueJsx(),
|
|
731
786
|
createLegacy(viteEnv),
|
|
@@ -784,11 +839,62 @@ function createDefaultAppConfig(config) {
|
|
|
784
839
|
chunkSizeWarningLimit: 2e3,
|
|
785
840
|
rolldownOptions: { output: {
|
|
786
841
|
entryFileNames: `assets/entry/[name]-[hash]-${timestamp}.js`,
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
842
|
+
strictExecutionOrder: true,
|
|
843
|
+
codeSplitting: {
|
|
844
|
+
minSize: 2e4,
|
|
845
|
+
groups: [
|
|
846
|
+
{
|
|
847
|
+
name: "antd-vendor",
|
|
848
|
+
test: /[\\/]node_modules[\\/].*ant-design-vue/,
|
|
849
|
+
priority: 30
|
|
850
|
+
},
|
|
851
|
+
{
|
|
852
|
+
name: "antd-icons-vendor",
|
|
853
|
+
test: /[\\/]node_modules[\\/].*@ant-design[\\/]icons-vue/,
|
|
854
|
+
priority: 30
|
|
855
|
+
},
|
|
856
|
+
{
|
|
857
|
+
name: "antd-deps-vendor",
|
|
858
|
+
test: /[\\/]node_modules[\\/].*@ant-design[\\/](?!icons-vue)/,
|
|
859
|
+
priority: 28
|
|
860
|
+
},
|
|
861
|
+
{
|
|
862
|
+
name: "vue-vendor",
|
|
863
|
+
test: /[\\/]node_modules[\\/].*[\\/](vue|vue-router|pinia|@vue)[\\/]/,
|
|
864
|
+
priority: 25
|
|
865
|
+
},
|
|
866
|
+
{
|
|
867
|
+
name: "vueuse-vendor",
|
|
868
|
+
test: /[\\/]node_modules[\\/].*@vueuse[\\/]/,
|
|
869
|
+
priority: 20
|
|
870
|
+
},
|
|
871
|
+
{
|
|
872
|
+
name: "lodash-vendor",
|
|
873
|
+
test: /[\\/]node_modules[\\/].*lodash-es[\\/]/,
|
|
874
|
+
priority: 20
|
|
875
|
+
},
|
|
876
|
+
{
|
|
877
|
+
name: "crypto-vendor",
|
|
878
|
+
test: /[\\/]node_modules[\\/].*(jsencrypt|zxcvbn|md5)[\\/]/,
|
|
879
|
+
priority: 20
|
|
880
|
+
},
|
|
881
|
+
{
|
|
882
|
+
name: "lottie-vendor",
|
|
883
|
+
test: /[\\/]node_modules[\\/].*lottie-web[\\/]/,
|
|
884
|
+
priority: 20
|
|
885
|
+
},
|
|
886
|
+
{
|
|
887
|
+
name: "http-vendor",
|
|
888
|
+
test: /[\\/]node_modules[\\/].*(axios|alova|@alova)[\\/]/,
|
|
889
|
+
priority: 20
|
|
890
|
+
},
|
|
891
|
+
{
|
|
892
|
+
name: "vendor",
|
|
893
|
+
test: /[\\/]node_modules[\\/]/,
|
|
894
|
+
priority: 10
|
|
895
|
+
}
|
|
896
|
+
]
|
|
897
|
+
}
|
|
792
898
|
} }
|
|
793
899
|
},
|
|
794
900
|
plugins: createVitePlugins(env, isBuild, config, "app")
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pubinfo/vite",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.1.10
|
|
4
|
+
"version": "2.1.10",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./dist/index.d.mts",
|
|
@@ -19,53 +19,53 @@
|
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"pinia": "^3.0.4",
|
|
22
|
-
"typescript": "^5.
|
|
23
|
-
"vue": "^3.5.
|
|
24
|
-
"vue-router": "^
|
|
25
|
-
"vue-tsc": "^3.
|
|
22
|
+
"typescript": "^5.9.3",
|
|
23
|
+
"vue": "^3.5.28",
|
|
24
|
+
"vue-router": "^5.0.2",
|
|
25
|
+
"vue-tsc": "^3.2.4"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@pubinfo/unplugin-openapi": "^0.9.1",
|
|
29
29
|
"@vitejs/plugin-legacy": "^7.2.1",
|
|
30
|
-
"@vitejs/plugin-vue": "^6.0.
|
|
31
|
-
"@vitejs/plugin-vue-jsx": "^5.1.
|
|
32
|
-
"@volar/typescript": "^2.4.
|
|
33
|
-
"@vue/language-core": "^3.
|
|
30
|
+
"@vitejs/plugin-vue": "^6.0.4",
|
|
31
|
+
"@vitejs/plugin-vue-jsx": "^5.1.4",
|
|
32
|
+
"@volar/typescript": "^2.4.28",
|
|
33
|
+
"@vue/language-core": "^3.2.4",
|
|
34
34
|
"abort-controller": "^3.0.0",
|
|
35
35
|
"boxen": "^8.0.1",
|
|
36
|
-
"chalk": "^5.
|
|
36
|
+
"chalk": "^5.6.2",
|
|
37
37
|
"dayjs": "^1.11.19",
|
|
38
38
|
"fast-glob": "^3.3.3",
|
|
39
|
-
"fs-extra": "^11.3.
|
|
39
|
+
"fs-extra": "^11.3.3",
|
|
40
40
|
"jszip": "^3.10.1",
|
|
41
|
-
"lodash-es": "^4.17.
|
|
42
|
-
"magic-string": "^0.30.
|
|
41
|
+
"lodash-es": "^4.17.23",
|
|
42
|
+
"magic-string": "^0.30.21",
|
|
43
43
|
"micromatch": "^4.0.8",
|
|
44
44
|
"picomatch": "^4.0.3",
|
|
45
45
|
"pkg-types": "^2.3.0",
|
|
46
|
-
"terser": "^5.
|
|
47
|
-
"unocss": "^66.
|
|
48
|
-
"unplugin-auto-import": "^
|
|
49
|
-
"unplugin-icons": "^
|
|
50
|
-
"unplugin-vue-components": "^
|
|
51
|
-
"vite": "^8.0.0-beta.
|
|
46
|
+
"terser": "^5.46.0",
|
|
47
|
+
"unocss": "^66.6.0",
|
|
48
|
+
"unplugin-auto-import": "^21.0.0",
|
|
49
|
+
"unplugin-icons": "^23.0.1",
|
|
50
|
+
"unplugin-vue-components": "^31.0.0",
|
|
51
|
+
"vite": "^8.0.0-beta.13",
|
|
52
52
|
"vite-plugin-compression": "^0.5.1",
|
|
53
|
-
"vite-plugin-env-runtime": "^0.3.
|
|
54
|
-
"vite-plugin-fake-server": "^2.2.
|
|
53
|
+
"vite-plugin-env-runtime": "^0.3.7",
|
|
54
|
+
"vite-plugin-fake-server": "^2.2.2",
|
|
55
55
|
"vite-plugin-lib-inject-css": "^2.2.2",
|
|
56
|
-
"vite-plugin-vue-devtools": "^8.0.
|
|
57
|
-
"@pubinfo/devtools": "2.1.10
|
|
58
|
-
"@pubinfo/shared": "2.1.10
|
|
56
|
+
"vite-plugin-vue-devtools": "^8.0.6",
|
|
57
|
+
"@pubinfo/devtools": "2.1.10",
|
|
58
|
+
"@pubinfo/shared": "2.1.10"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/fs-extra": "^11.0.4",
|
|
62
62
|
"@types/lodash-es": "^4.17.12",
|
|
63
|
-
"@types/micromatch": "^4.0.
|
|
64
|
-
"@types/node": "^
|
|
63
|
+
"@types/micromatch": "^4.0.10",
|
|
64
|
+
"@types/node": "^25.2.2",
|
|
65
65
|
"@types/picomatch": "^4.0.2",
|
|
66
66
|
"pinia": "^3.0.4",
|
|
67
|
-
"vue": "^3.5.
|
|
68
|
-
"vue-router": "^
|
|
67
|
+
"vue": "^3.5.28",
|
|
68
|
+
"vue-router": "^5.0.2"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"dev": "tsdown --watch",
|