@4399ywkf/core 5.0.7 → 5.0.8

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.d.ts CHANGED
@@ -107,11 +107,17 @@ declare class YwkfGeneratorPlugin {
107
107
  * 初始化插件钩子
108
108
  */
109
109
  private initialize;
110
+ private resetState;
111
+ private regenerate;
110
112
  apply(compiler: Compiler): void;
111
113
  /**
112
114
  * 监听页面目录变化
113
115
  */
114
116
  private watchPages;
117
+ /**
118
+ * 监听配置文件变化,重新加载配置并重新生成 .ywkf 文件
119
+ */
120
+ private watchConfig;
115
121
  }
116
122
 
117
123
  interface GarfishPluginOptions {
package/dist/index.js CHANGED
@@ -480,7 +480,7 @@ function generateEntry(config, injections = {}) {
480
480
  startupBody = [
481
481
  `(async () => {`,
482
482
  ...topLevel.map((l) => ` ${l}`),
483
- ` runApp();`,
483
+ ` await runApp();`,
484
484
  `})();`
485
485
  ].join("\n");
486
486
  } else {
@@ -994,6 +994,16 @@ var YwkfGeneratorPlugin = class {
994
994
  );
995
995
  this.initialized = true;
996
996
  }
997
+ resetState() {
998
+ this.initialized = false;
999
+ this.pluginHooks = [];
1000
+ this.generator = null;
1001
+ }
1002
+ async regenerate() {
1003
+ if (this.generator) {
1004
+ await this.generator.generate();
1005
+ }
1006
+ }
997
1007
  apply(compiler) {
998
1008
  const pluginName = "YwkfGeneratorPlugin";
999
1009
  compiler.hooks.beforeCompile.tapAsync(pluginName, async (params, callback) => {
@@ -1010,6 +1020,7 @@ var YwkfGeneratorPlugin = class {
1010
1020
  });
1011
1021
  if (this.options.isDev && !this.isWatching) {
1012
1022
  this.watchPages();
1023
+ this.watchConfig();
1013
1024
  }
1014
1025
  }
1015
1026
  /**
@@ -1045,6 +1056,43 @@ var YwkfGeneratorPlugin = class {
1045
1056
  watcher.close();
1046
1057
  });
1047
1058
  }
1059
+ /**
1060
+ * 监听配置文件变化,重新加载配置并重新生成 .ywkf 文件
1061
+ */
1062
+ watchConfig() {
1063
+ const { cwd } = this.options;
1064
+ const configPath = findConfigFile(cwd);
1065
+ if (!configPath) {
1066
+ return;
1067
+ }
1068
+ let debounceTimer = null;
1069
+ const watcher = watch(configPath, async () => {
1070
+ if (debounceTimer) {
1071
+ clearTimeout(debounceTimer);
1072
+ }
1073
+ debounceTimer = setTimeout(async () => {
1074
+ try {
1075
+ console.log(`
1076
+ [ywkf] \u68C0\u6D4B\u5230\u914D\u7F6E\u6587\u4EF6\u53D8\u5316\uFF0C\u91CD\u65B0\u751F\u6210 .ywkf \u76EE\u5F55...
1077
+ `);
1078
+ const userConfig = await loadConfigFile(configPath);
1079
+ const newConfig = mergeConfig(userConfig);
1080
+ this.options.config = newConfig;
1081
+ this.options.pluginConfigs = newConfig.plugins;
1082
+ this.resetState();
1083
+ await this.initialize();
1084
+ await this.regenerate();
1085
+ console.log(` [ywkf] .ywkf \u76EE\u5F55\u5DF2\u91CD\u65B0\u751F\u6210\u3002\u90E8\u5206\u914D\u7F6E\u53D8\u66F4\uFF08\u5982\u7AEF\u53E3\u3001\u4EE3\u7406\uFF09\u9700\u91CD\u542F dev server \u751F\u6548\u3002
1086
+ `);
1087
+ } catch (error) {
1088
+ console.error(` [ywkf] \u914D\u7F6E\u91CD\u8F7D\u5931\u8D25:`, error);
1089
+ }
1090
+ }, 500);
1091
+ });
1092
+ process.on("exit", () => {
1093
+ watcher.close();
1094
+ });
1095
+ }
1048
1096
  };
1049
1097
 
1050
1098
  // src/rspack/base.ts