@proteus-vue/plugin-vite 0.2.0-beta.4 → 0.2.0-beta.6

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.
@@ -20,6 +20,17 @@ export interface GenRoutesOptions {
20
20
  dependencies?: Record<string, string>;
21
21
  preload?: string[];
22
22
  }>;
23
+ /**
24
+ * ★Web 目标只生成**应用侧路由表**(2026-09-19 修外部实战报告的第 3 条阻断项):
25
+ * `auto-routes.ts` 是 **双端共用** 产物(Web 的 RouterView 与 MP 的 app.json 同源),
26
+ * 但此前 gen-routes 只在 MP 目标被调用(`needsGenRoutes: isMp`)→ 使用 `proteus build --target web`
27
+ * 的工程新增页面后路由表不更新 → **页面 404**(外部项目实测:新增 `src/pages/editor/` 后
28
+ * Web 构建成功但路由表未收录)。
29
+ * `webOnly: true` 时:只 `scanPages → buildRoutes → validate → writeAutoRoutes`,
30
+ * **跳过 MP 专属产物**(app.json/page.json/component.json/project.config.json,web 构建不需要)
31
+ * 且**不清理 `dist/mp-weixin`**(否则会把已构建的 MP 产物删掉——那不属于 web 构建的职责)。
32
+ */
33
+ webOnly?: boolean;
23
34
  }
24
35
  /**
25
36
  * 运行路由表生成(纯函数,可单测):清理 dist 产物 → 扫描页面 → 生成 auto-routes/app.json/page.json/component.json
package/dist/index.js CHANGED
@@ -118,7 +118,7 @@ function runGenRoutes(options) {
118
118
  const APP_DIR = path2.resolve(ROOT, path2.dirname(config.pagesDir));
119
119
  const OUT_DIR = path2.join(ROOT, "dist", "mp-weixin");
120
120
  const FW_COMPONENTS = options.componentsDir ? path2.resolve(ROOT, options.componentsDir) : resolveComponentsRoot(ROOT);
121
- if (!fs2.existsSync(FW_COMPONENTS)) {
121
+ if (!fs2.existsSync(FW_COMPONENTS) && appUsesFrameworkComponents(APP_DIR)) {
122
122
  console.warn(
123
123
  `[gen-routes] \u672A\u627E\u5230\u8BED\u4E49\u7EC4\u4EF6\u5E93 @proteus-vue/components\uFF08\u89E3\u6790\u4E3A ${FW_COMPONENTS}\uFF09\u2014\u2014p-* \u7EC4\u4EF6\u5C06\u4E0D\u88AB\u6CE8\u518C\uFF08\u9875\u9762 usingComponents \u7F3A\u5931 \u2192 WXML \u6574\u5757\u4E0D\u6E32\u67D3\uFF09\u3002\u8BF7\u786E\u8BA4\u5DF2\u5B89\u88C5\u4F9D\u8D56\uFF08npm i / pnpm i\uFF09\u3002`
124
124
  );
@@ -148,6 +148,18 @@ function runGenRoutes(options) {
148
148
  }
149
149
  return acc;
150
150
  }
151
+ function appUsesFrameworkComponents(appDir) {
152
+ for (const f of walkVueFiles2(appDir)) {
153
+ let src;
154
+ try {
155
+ src = fs2.readFileSync(f, "utf8");
156
+ } catch {
157
+ continue;
158
+ }
159
+ if (/<[pP]-[a-z][\w-]*[\s/>]/.test(src) || /<P[A-Z][\w]*[\s/>]/.test(src)) return true;
160
+ }
161
+ return false;
162
+ }
151
163
  function resolveConfigMeta(configMeta, pageRel) {
152
164
  if (!configMeta) return void 0;
153
165
  let dirMeta;
@@ -294,6 +306,10 @@ function runGenRoutes(options) {
294
306
  return ` { ${parts.join(", ")} },`;
295
307
  }
296
308
  function writeAutoRoutes(routes2) {
309
+ if (!rc.routesOutput) {
310
+ console.log("[gen-routes] routesOutput \u4E3A\u7A7A \u2192 \u6309\u914D\u7F6E**\u8DF3\u8FC7**\u5E94\u7528\u4FA7\u8DEF\u7531\u8868\u751F\u6210\uFF08\u5DE5\u7A0B\u81EA\u5E26\u8DEF\u7531\u673A\u5236\uFF09");
311
+ return;
312
+ }
297
313
  const lines = [
298
314
  `// ${rc.routesOutput} \u2014\u2014 \u5E94\u7528\u4FA7\u8DEF\u7531\u8868\uFF08AUTO-GENERATED by scripts/gen-routes.ts\uFF0C\u52FF\u624B\u52A8\u7F16\u8F91\uFF09`,
299
315
  "// \u2605\u62C6\u5305\u6B65\u9AA4 4\uFF1Aauto-routes \u968F\u5E94\u7528\u5B58\u653E\uFF08\u5DE5\u5382\u5316\u540E\u8DEF\u7531\u8868\u7531\u5E94\u7528\u6CE8\u5165 createRouter\uFF09\uFF0C\u4E0D\u518D\u5C5E\u4E8E @proteus-vue/router \u5305",
@@ -715,10 +731,15 @@ function runGenRoutes(options) {
715
731
  fs2.writeFileSync(path2.join(OUT_DIR, "project.config.json"), JSON.stringify(projectConfig, null, 2) + "\n");
716
732
  console.log(`[gen-routes] \u5DF2\u751F\u6210 dist/mp-weixin/project.config.json\uFF08appid=${config.appid}\uFF0Cprojectname=${projectName}\uFF09`);
717
733
  }
718
- fs2.rmSync(OUT_DIR, { recursive: true, force: true });
719
734
  const pages = scanPages();
720
735
  const routes = buildRoutes(pages);
721
736
  validate(pages, routes);
737
+ if (options.webOnly) {
738
+ writeAutoRoutes(routes);
739
+ console.log(`[gen-routes] \uFF08web \u76EE\u6807\uFF09\u5DF2\u66F4\u65B0\u5E94\u7528\u4FA7\u8DEF\u7531\u8868\uFF1A\u5171 ${pages.length} \u4E2A\u9875\u9762`);
740
+ return;
741
+ }
742
+ fs2.rmSync(OUT_DIR, { recursive: true, force: true });
722
743
  writeAutoRoutes(routes);
723
744
  writeAppJson(pages, routes);
724
745
  writePageJsons(pages);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proteus-vue/plugin-vite",
3
- "version": "0.2.0-beta.4",
3
+ "version": "0.2.0-beta.6",
4
4
  "description": "Proteus Vite 插件(mp-weixin 编译管线适配层)+ gen-routes 路由表生成器",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -21,7 +21,7 @@
21
21
  "dependencies": {
22
22
  "@proteus-vue/compiler": "0.3.0-beta.3",
23
23
  "@proteus-vue/module": "0.1.1-beta.0",
24
- "@proteus-vue/router": "0.2.0-beta.4",
24
+ "@proteus-vue/router": "0.2.0-beta.5",
25
25
  "@proteus-vue/types": "0.2.0-beta.2",
26
26
  "esbuild": "^0.28.2",
27
27
  "sass": "^1.103.1",