miaoda-react-devkit 0.1.1-beta.0 → 0.1.1-beta.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/cloud/vite.config.js +118 -0
- package/dist/index.cjs +622 -47
- package/dist/index.d.cts +305 -41
- package/dist/index.d.ts +305 -41
- package/dist/index.js +613 -49
- package/dist/stubs/sentry-react-noop-stub.js +78 -0
- package/dist/stubs/sentry-react-stub.js +547 -86
- package/dist/vite/index.cjs +80 -1
- package/dist/vite/index.d.cts +15 -1
- package/dist/vite/index.d.ts +15 -1
- package/dist/vite/index.js +78 -1
- package/package.json +8 -1
- package/README.md +0 -41
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// cloud/vite.config.ts
|
|
2
|
+
import * as vite from "vite";
|
|
3
|
+
import { loadConfigFromFile, mergeConfig } from "vite";
|
|
4
|
+
import { withSentryStub, hmrTogglePlugin } from "../dist/vite/index.js";
|
|
5
|
+
import {
|
|
6
|
+
makeTagger,
|
|
7
|
+
injectedGuiListenerPlugin,
|
|
8
|
+
injectOnErrorPlugin,
|
|
9
|
+
monitorPlugin,
|
|
10
|
+
fontsCodePlugin,
|
|
11
|
+
mdClickPlugin,
|
|
12
|
+
extractRouterPlugin,
|
|
13
|
+
patchSupabasePlugins
|
|
14
|
+
} from "miaoda-sc-plugin";
|
|
15
|
+
import path from "path";
|
|
16
|
+
import fs from "fs";
|
|
17
|
+
var projectRoot = process.cwd();
|
|
18
|
+
var appType = process.env.DEVKIT_APP_TYPE ?? "freestyle";
|
|
19
|
+
var cdnHost = process.env.DEVKIT_CDN_HOST ?? "resource-static.cdn.bcebos.com";
|
|
20
|
+
var env = process.env.DEVKIT_ENV ?? "";
|
|
21
|
+
var sentryDsn = process.env.DEVKIT_SENTRY_DSN ?? "";
|
|
22
|
+
var miaodaEnv = process.env.DEVKIT_MIAODA_ENV ?? "";
|
|
23
|
+
var appId = process.env.DEVKIT_APP_ID ?? "";
|
|
24
|
+
var isOnline = env === "online";
|
|
25
|
+
var loaded = await loadConfigFromFile(
|
|
26
|
+
{ command: "serve", mode: "development" },
|
|
27
|
+
path.join(projectRoot, "vite.config.ts"),
|
|
28
|
+
projectRoot
|
|
29
|
+
);
|
|
30
|
+
var projectConfig = loaded?.config ?? {};
|
|
31
|
+
var configPath = path.join(projectRoot, "vite.config.ts");
|
|
32
|
+
if (!loaded) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`[miaoda-devkit] \u627E\u4E0D\u5230\u9879\u76EE vite \u914D\u7F6E\uFF1A${configPath}
|
|
35
|
+
\u8BF7\u786E\u8BA4\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u5B58\u5728 vite.config.ts`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
var plugins = (projectConfig.plugins ?? []).flat(Infinity).filter((p) => !!p);
|
|
39
|
+
var hasReact = plugins.some((p) => p.name === "vite:react-babel" || p.name === "vite:react-swc");
|
|
40
|
+
if (!hasReact) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`[miaoda-devkit] \u9879\u76EE vite \u914D\u7F6E\u7F3A\u5C11 React \u63D2\u4EF6\u3002
|
|
43
|
+
\u8BF7\u5728 ${configPath} \u7684 plugins \u4E2D\u6DFB\u52A0 react()\uFF08@vitejs/plugin-react \u6216 @vitejs/plugin-react-swc\uFF09`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
var possibleEntries = ["./src/main.tsx", "./src/main.ts", "./src/index.tsx", "./src/index.ts"];
|
|
47
|
+
var warmupFiles = possibleEntries.filter((e) => fs.existsSync(path.join(projectRoot, e)));
|
|
48
|
+
var SENTRY_IMPORT_RE = /from\s+['"]@sentry\/react['"]/;
|
|
49
|
+
function entryHasSentryImport(root, entries) {
|
|
50
|
+
for (const entry of entries) {
|
|
51
|
+
const fullPath = path.join(root, entry);
|
|
52
|
+
if (!fs.existsSync(fullPath)) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
if (SENTRY_IMPORT_RE.test(fs.readFileSync(fullPath, "utf-8"))) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
} catch {
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
var hasSentryReact = entryHasSentryImport(projectRoot, possibleEntries);
|
|
65
|
+
var viteVersionInfo = {
|
|
66
|
+
version: vite.version,
|
|
67
|
+
rollupVersion: vite.rollupVersion ?? null,
|
|
68
|
+
rolldownVersion: vite.rolldownVersion ?? null,
|
|
69
|
+
isRolldownVite: "rolldownVersion" in vite
|
|
70
|
+
};
|
|
71
|
+
var injectedGuiUrl = `https://${cdnHost}/common/v2/${isOnline ? "" : `${env}/`}injected.js`;
|
|
72
|
+
var cloudPlugins = [
|
|
73
|
+
...hasSentryReact ? [withSentryStub()] : [monitorPlugin({
|
|
74
|
+
scriptSrc: `https://${cdnHost}/sentry/browser.sentry.min.js`,
|
|
75
|
+
sentryDsn,
|
|
76
|
+
environment: miaodaEnv,
|
|
77
|
+
appId
|
|
78
|
+
})],
|
|
79
|
+
// web 类型需要 DOM 节点打标(GUI使用)
|
|
80
|
+
...appType === "web" ? [
|
|
81
|
+
makeTagger(),
|
|
82
|
+
mdClickPlugin({ appType }),
|
|
83
|
+
fontsCodePlugin(),
|
|
84
|
+
injectedGuiListenerPlugin({ path: injectedGuiUrl })
|
|
85
|
+
] : [],
|
|
86
|
+
injectedGuiListenerPlugin({ path: injectedGuiUrl }),
|
|
87
|
+
injectOnErrorPlugin(),
|
|
88
|
+
hmrTogglePlugin(),
|
|
89
|
+
extractRouterPlugin(),
|
|
90
|
+
patchSupabasePlugins()
|
|
91
|
+
];
|
|
92
|
+
var cloudConfig = {
|
|
93
|
+
define: {
|
|
94
|
+
__VITE_INFO__: JSON.stringify(viteVersionInfo)
|
|
95
|
+
},
|
|
96
|
+
// 将缓存目录固定到项目本地,避免在 /workspace/node_modules/ 下创建
|
|
97
|
+
cacheDir: path.resolve(projectRoot, "node_modules/.vite"),
|
|
98
|
+
server: {
|
|
99
|
+
warmup: warmupFiles.length > 0 ? { clientFiles: warmupFiles } : {}
|
|
100
|
+
},
|
|
101
|
+
plugins: cloudPlugins
|
|
102
|
+
};
|
|
103
|
+
function dedupePlugins(config) {
|
|
104
|
+
if (!Array.isArray(config.plugins)) return config;
|
|
105
|
+
const flattened = config.plugins.flat(Infinity);
|
|
106
|
+
const seen = /* @__PURE__ */ new Set();
|
|
107
|
+
const deduped = flattened.reverse().filter((p) => {
|
|
108
|
+
if (!p || !p.name) return true;
|
|
109
|
+
if (seen.has(p.name)) return false;
|
|
110
|
+
seen.add(p.name);
|
|
111
|
+
return true;
|
|
112
|
+
}).reverse();
|
|
113
|
+
return { ...config, plugins: deduped };
|
|
114
|
+
}
|
|
115
|
+
var vite_config_default = dedupePlugins(mergeConfig(projectConfig, cloudConfig));
|
|
116
|
+
export {
|
|
117
|
+
vite_config_default as default
|
|
118
|
+
};
|