@mbws/plugin-sdk 0.2.0 → 0.2.1
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/vite.js +23 -13
- package/package.json +1 -1
package/dist/vite.js
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
*
|
|
5
5
|
* 承担四件事(对齐原脚手架模板内联版语义):
|
|
6
6
|
* - define 注入插件编号(build/serve 都注入),serve 额外注入 dev 契约前缀;
|
|
7
|
-
* - 缺省补 base: "./"(产物在 OSS 子目录 / registry
|
|
8
|
-
* rollupOptions.input(panel.html / viewer.html
|
|
7
|
+
* - 缺省补 base: "./"(产物在 OSS 子目录 / registry 代理路径下托管)、双入口
|
|
8
|
+
* rollupOptions.input(panel.html / viewer.html)与 build.outDir(解包形态目录,
|
|
9
|
+
* 与 manifest 同目录——缺省 dist/ 根会两处分离破坏 CI 打包约定),用户已设项不覆盖;
|
|
9
10
|
* - dev 虚拟供给 /manifest.json(buildManifest 派生,与 build 产物同源);
|
|
10
11
|
* - dev 转发 /__mbws__/api/* 到后端(Node 全局 fetch,不走 server.proxy——
|
|
11
12
|
* 用户自己的 proxy 配置自由,互不干扰);
|
|
@@ -44,6 +45,8 @@ export function mbwsVitePlugin(opts) {
|
|
|
44
45
|
let projectRoot = process.cwd();
|
|
45
46
|
// manifest 是纯派生物,构建/供给共用同一序列化姿势(尾换行对齐文件写习惯)
|
|
46
47
|
const manifestJson = () => `${JSON.stringify(buildManifest(config), null, 2)}\n`;
|
|
48
|
+
// 解包形态目录 <id>@<version>/:静态产物与 manifest 同目录(CI 的 tar -C 按它整目录打包)
|
|
49
|
+
const distDir = () => path.resolve(projectRoot, `dist/${config.id}@${config.version}`);
|
|
47
50
|
return {
|
|
48
51
|
name: "mbws-plugin",
|
|
49
52
|
config(userConfig, { command }) {
|
|
@@ -60,21 +63,28 @@ export function mbwsVitePlugin(opts) {
|
|
|
60
63
|
// 相对 base:产物在 OSS 子目录 / registry 代理路径下托管,资源引用必须是 ./ 相对路径
|
|
61
64
|
if (!userConfig.base)
|
|
62
65
|
incremental.base = "./";
|
|
63
|
-
//
|
|
66
|
+
// 构建缺省(用户已设项不覆盖):
|
|
67
|
+
// - outDir 必须钉到解包形态目录——vite 缺省吐 dist/ 根会与 closeBundle 写的
|
|
68
|
+
// manifest.json 分离,CI 的 tar 只打包到孤零零的 manifest(解包形态约定被破坏)
|
|
69
|
+
// - 只打包宿主要装载的两个入口;根 index.html 欢迎页是 dev 导航,不进产物
|
|
70
|
+
const buildDefaults = {};
|
|
71
|
+
if (!userConfig.build?.outDir)
|
|
72
|
+
buildDefaults.outDir = distDir();
|
|
64
73
|
if (!userConfig.build?.rollupOptions?.input) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
input: [
|
|
68
|
-
path.resolve(projectRoot, "panel.html"),
|
|
69
|
-
path.resolve(projectRoot, "viewer.html"),
|
|
70
|
-
],
|
|
71
|
-
},
|
|
74
|
+
buildDefaults.rollupOptions = {
|
|
75
|
+
input: [path.resolve(projectRoot, "panel.html"), path.resolve(projectRoot, "viewer.html")],
|
|
72
76
|
};
|
|
73
77
|
}
|
|
74
|
-
|
|
78
|
+
if (Object.keys(buildDefaults).length > 0)
|
|
79
|
+
incremental.build = buildDefaults;
|
|
80
|
+
// 依赖预构建不消费顶层 define,漏了 SDK 里的注入读取在 dev 侧失效。
|
|
81
|
+
// vite 8 依赖优化换 Rolldown:esbuildOptions 已废弃(启动即告警);rolldown 的
|
|
82
|
+
// define 在 transform 子对象下(rolldown InputOptions.transform.define)
|
|
75
83
|
if (command === "serve") {
|
|
76
84
|
incremental.optimizeDeps = {
|
|
77
|
-
|
|
85
|
+
rolldownOptions: {
|
|
86
|
+
transform: { define: { __MBWS_PLUGIN_CODE__: JSON.stringify(config.id) } },
|
|
87
|
+
},
|
|
78
88
|
};
|
|
79
89
|
}
|
|
80
90
|
return incremental;
|
|
@@ -98,7 +108,7 @@ export function mbwsVitePlugin(opts) {
|
|
|
98
108
|
},
|
|
99
109
|
closeBundle() {
|
|
100
110
|
// 产物直出解包形态目录 <id>@<version>/,桌面 MBWS_DEV_PLUGIN_DIR 指向 dist 即装载
|
|
101
|
-
const outDir =
|
|
111
|
+
const outDir = distDir();
|
|
102
112
|
// mkdir 容错:在线构建场景 outDir 被平台覆盖,本目录可能不存在(写失败会炸构建)
|
|
103
113
|
fs.mkdirSync(outDir, { recursive: true });
|
|
104
114
|
fs.writeFileSync(path.join(outDir, "manifest.json"), manifestJson());
|