@4399ywkf/core 5.0.6 → 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/cli/index.js CHANGED
@@ -490,7 +490,7 @@ function generateEntry(config, injections = {}) {
490
490
  startupBody = [
491
491
  `(async () => {`,
492
492
  ...topLevel.map((l) => ` ${l}`),
493
- ` runApp();`,
493
+ ` await runApp();`,
494
494
  `})();`
495
495
  ].join("\n");
496
496
  } else {
@@ -1004,6 +1004,16 @@ var YwkfGeneratorPlugin = class {
1004
1004
  );
1005
1005
  this.initialized = true;
1006
1006
  }
1007
+ resetState() {
1008
+ this.initialized = false;
1009
+ this.pluginHooks = [];
1010
+ this.generator = null;
1011
+ }
1012
+ async regenerate() {
1013
+ if (this.generator) {
1014
+ await this.generator.generate();
1015
+ }
1016
+ }
1007
1017
  apply(compiler) {
1008
1018
  const pluginName = "YwkfGeneratorPlugin";
1009
1019
  compiler.hooks.beforeCompile.tapAsync(pluginName, async (params, callback) => {
@@ -1020,6 +1030,7 @@ var YwkfGeneratorPlugin = class {
1020
1030
  });
1021
1031
  if (this.options.isDev && !this.isWatching) {
1022
1032
  this.watchPages();
1033
+ this.watchConfig();
1023
1034
  }
1024
1035
  }
1025
1036
  /**
@@ -1055,6 +1066,43 @@ var YwkfGeneratorPlugin = class {
1055
1066
  watcher.close();
1056
1067
  });
1057
1068
  }
1069
+ /**
1070
+ * 监听配置文件变化,重新加载配置并重新生成 .ywkf 文件
1071
+ */
1072
+ watchConfig() {
1073
+ const { cwd } = this.options;
1074
+ const configPath = findConfigFile(cwd);
1075
+ if (!configPath) {
1076
+ return;
1077
+ }
1078
+ let debounceTimer = null;
1079
+ const watcher = watch(configPath, async () => {
1080
+ if (debounceTimer) {
1081
+ clearTimeout(debounceTimer);
1082
+ }
1083
+ debounceTimer = setTimeout(async () => {
1084
+ try {
1085
+ console.log(`
1086
+ [ywkf] \u68C0\u6D4B\u5230\u914D\u7F6E\u6587\u4EF6\u53D8\u5316\uFF0C\u91CD\u65B0\u751F\u6210 .ywkf \u76EE\u5F55...
1087
+ `);
1088
+ const userConfig = await loadConfigFile(configPath);
1089
+ const newConfig = mergeConfig(userConfig);
1090
+ this.options.config = newConfig;
1091
+ this.options.pluginConfigs = newConfig.plugins;
1092
+ this.resetState();
1093
+ await this.initialize();
1094
+ await this.regenerate();
1095
+ 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
1096
+ `);
1097
+ } catch (error) {
1098
+ console.error(` [ywkf] \u914D\u7F6E\u91CD\u8F7D\u5931\u8D25:`, error);
1099
+ }
1100
+ }, 500);
1101
+ });
1102
+ process.on("exit", () => {
1103
+ watcher.close();
1104
+ });
1105
+ }
1058
1106
  };
1059
1107
 
1060
1108
  // src/rspack/base.ts