@pubinfo-pr/vite 0.224.1 → 0.225.2
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 +116 -11
- package/package.json +3 -3
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";
|
|
@@ -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: `lottie-${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) {
|
|
@@ -635,7 +689,7 @@ function createComponents() {
|
|
|
635
689
|
"PubinfoIcon"
|
|
636
690
|
].includes(name)) return {
|
|
637
691
|
name,
|
|
638
|
-
from: "pubinfo
|
|
692
|
+
from: "pubinfo"
|
|
639
693
|
};
|
|
640
694
|
}
|
|
641
695
|
}
|
|
@@ -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),
|
|
@@ -772,8 +827,8 @@ function createDefaultAppConfig(config) {
|
|
|
772
827
|
warmup: { clientFiles: ["./index.html"] }
|
|
773
828
|
},
|
|
774
829
|
optimizeDeps: { exclude: [
|
|
775
|
-
"pubinfo
|
|
776
|
-
"@pubinfo
|
|
830
|
+
"pubinfo",
|
|
831
|
+
"@pubinfo/core",
|
|
777
832
|
"alova"
|
|
778
833
|
] },
|
|
779
834
|
resolve: { alias: alias(root) },
|
|
@@ -784,11 +839,61 @@ 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
|
+
codeSplitting: {
|
|
843
|
+
minSize: 2e4,
|
|
844
|
+
groups: [
|
|
845
|
+
{
|
|
846
|
+
name: "antd-vendor",
|
|
847
|
+
test: /[\\/]node_modules[\\/].*ant-design-vue/,
|
|
848
|
+
priority: 30
|
|
849
|
+
},
|
|
850
|
+
{
|
|
851
|
+
name: "antd-icons-vendor",
|
|
852
|
+
test: /[\\/]node_modules[\\/].*@ant-design[\\/]icons-vue/,
|
|
853
|
+
priority: 30
|
|
854
|
+
},
|
|
855
|
+
{
|
|
856
|
+
name: "antd-deps-vendor",
|
|
857
|
+
test: /[\\/]node_modules[\\/].*@ant-design[\\/](?!icons-vue)/,
|
|
858
|
+
priority: 28
|
|
859
|
+
},
|
|
860
|
+
{
|
|
861
|
+
name: "vue-vendor",
|
|
862
|
+
test: /[\\/]node_modules[\\/].*[\\/](vue|vue-router|pinia|@vue)[\\/]/,
|
|
863
|
+
priority: 25
|
|
864
|
+
},
|
|
865
|
+
{
|
|
866
|
+
name: "vueuse-vendor",
|
|
867
|
+
test: /[\\/]node_modules[\\/].*@vueuse[\\/]/,
|
|
868
|
+
priority: 20
|
|
869
|
+
},
|
|
870
|
+
{
|
|
871
|
+
name: "lodash-vendor",
|
|
872
|
+
test: /[\\/]node_modules[\\/].*lodash-es[\\/]/,
|
|
873
|
+
priority: 20
|
|
874
|
+
},
|
|
875
|
+
{
|
|
876
|
+
name: "crypto-vendor",
|
|
877
|
+
test: /[\\/]node_modules[\\/].*(jsencrypt|zxcvbn|md5)[\\/]/,
|
|
878
|
+
priority: 20
|
|
879
|
+
},
|
|
880
|
+
{
|
|
881
|
+
name: "lottie-vendor",
|
|
882
|
+
test: /[\\/]node_modules[\\/].*lottie-web[\\/]/,
|
|
883
|
+
priority: 20
|
|
884
|
+
},
|
|
885
|
+
{
|
|
886
|
+
name: "http-vendor",
|
|
887
|
+
test: /[\\/]node_modules[\\/].*(axios|alova|@alova)[\\/]/,
|
|
888
|
+
priority: 20
|
|
889
|
+
},
|
|
890
|
+
{
|
|
891
|
+
name: "vendor",
|
|
892
|
+
test: /[\\/]node_modules[\\/]/,
|
|
893
|
+
priority: 10
|
|
894
|
+
}
|
|
895
|
+
]
|
|
896
|
+
}
|
|
792
897
|
} }
|
|
793
898
|
},
|
|
794
899
|
plugins: createVitePlugins(env, isBuild, config, "app")
|
|
@@ -805,8 +910,8 @@ function createDefaultModuleConfig(config) {
|
|
|
805
910
|
const env = loadEnv(mode, root);
|
|
806
911
|
return {
|
|
807
912
|
optimizeDeps: { exclude: [
|
|
808
|
-
"pubinfo
|
|
809
|
-
"@pubinfo
|
|
913
|
+
"pubinfo",
|
|
914
|
+
"@pubinfo/core",
|
|
810
915
|
"alova"
|
|
811
916
|
] },
|
|
812
917
|
resolve: { alias: alias(root) },
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pubinfo-pr/vite",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.225.2",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./dist/index.d.mts",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"vue-tsc": "^3.2.4"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@pubinfo-pr/devtools": "0.
|
|
29
|
-
"@pubinfo-pr/shared": "0.
|
|
28
|
+
"@pubinfo-pr/devtools": "0.225.2",
|
|
29
|
+
"@pubinfo-pr/shared": "0.225.2",
|
|
30
30
|
"@pubinfo/unplugin-openapi": "^0.9.1",
|
|
31
31
|
"@vitejs/plugin-legacy": "^7.2.1",
|
|
32
32
|
"@vitejs/plugin-vue": "^6.0.4",
|