@4399ywkf/core 5.0.32 → 5.1.2

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.
@@ -12,7 +12,9 @@ declare function findConfigFile(cwd: string): string | null;
12
12
  /**
13
13
  * 加载配置文件
14
14
  */
15
- declare function loadConfigFile(configPath: string): Promise<YwkfConfig>;
15
+ declare function loadConfigFile(configPath: string, opts?: {
16
+ fresh?: boolean;
17
+ }): Promise<YwkfConfig>;
16
18
  /**
17
19
  * 合并配置
18
20
  */
@@ -20,9 +22,12 @@ declare function mergeConfig(userConfig: YwkfConfig, baseConfig?: YwkfConfig): R
20
22
  /**
21
23
  * 解析并加载完整配置
22
24
  * @param cwd 工作目录
25
+ * @param opts.fresh 为 true 时对 .js/.mjs 配置破除 import 缓存(用于热重启)
23
26
  * @returns 合并后的完整配置
24
27
  */
25
- declare function resolveConfig(cwd: string): Promise<{
28
+ declare function resolveConfig(cwd: string, opts?: {
29
+ fresh?: boolean;
30
+ }): Promise<{
26
31
  config: Required<YwkfConfig>;
27
32
  configPath: string | null;
28
33
  }>;
@@ -367,8 +367,7 @@ var garfishPlugin = createPlugin((options = {}) => ({
367
367
  if (!master) {
368
368
  rspackConfig.output = {
369
369
  ...rspackConfig.output,
370
- library: finalAppName,
371
- libraryTarget: "umd",
370
+ library: { type: "umd", name: finalAppName },
372
371
  globalObject: "window",
373
372
  chunkLoadingGlobal: `garfish_${finalAppName}`
374
373
  };
@@ -2182,32 +2181,39 @@ function findConfigFile(cwd) {
2182
2181
  }
2183
2182
  return null;
2184
2183
  }
2185
- async function loadTsConfig(configPath) {
2184
+ async function loadTsConfig(configPath, fresh = false) {
2186
2185
  const jiti = (await import("jiti")).default;
2187
2186
  const loader = jiti(configPath, {
2188
- interopDefault: true
2187
+ interopDefault: true,
2188
+ // fresh(热重启)时必须禁用缓存:jiti 的 moduleCache 默认与 Node 原生 require 缓存集成,
2189
+ // 即使新建 jiti 实例,loader(configPath) 仍会命中 Node 全局缓存读回旧配置;
2190
+ // fsCache 为转译产物缓存,一并关闭以确保读到最新源码。
2191
+ ...fresh ? { moduleCache: false, fsCache: false } : {}
2189
2192
  });
2190
2193
  const config = loader(configPath);
2191
2194
  return config.default || config;
2192
2195
  }
2193
- async function loadJsConfig(configPath) {
2194
- const fileUrl = pathToFileURL(configPath).href;
2196
+ async function loadJsConfig(configPath, fresh = false) {
2197
+ let fileUrl = pathToFileURL(configPath).href;
2198
+ if (fresh) {
2199
+ fileUrl += `?t=${Date.now()}`;
2200
+ }
2195
2201
  const module = await import(fileUrl);
2196
2202
  return module.default || module;
2197
2203
  }
2198
- async function loadConfigFile(configPath) {
2204
+ async function loadConfigFile(configPath, opts = {}) {
2199
2205
  const ext = extname(configPath);
2200
2206
  if (ext === ".ts" || ext === ".mts") {
2201
- return loadTsConfig(configPath);
2207
+ return loadTsConfig(configPath, opts.fresh);
2202
2208
  }
2203
- return loadJsConfig(configPath);
2209
+ return loadJsConfig(configPath, opts.fresh);
2204
2210
  }
2205
2211
  function mergeConfig(userConfig, baseConfig = defaultConfig) {
2206
2212
  return deepmerge(baseConfig, userConfig, {
2207
2213
  arrayMerge: (_, sourceArray) => sourceArray
2208
2214
  });
2209
2215
  }
2210
- async function resolveConfig(cwd) {
2216
+ async function resolveConfig(cwd, opts = {}) {
2211
2217
  const configPath = findConfigFile(cwd);
2212
2218
  if (!configPath) {
2213
2219
  console.warn("\u26A0\uFE0F \u672A\u627E\u5230\u914D\u7F6E\u6587\u4EF6 (ywkf.config.ts)\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u914D\u7F6E");
@@ -2217,7 +2223,7 @@ async function resolveConfig(cwd) {
2217
2223
  };
2218
2224
  }
2219
2225
  try {
2220
- const userConfig = await loadConfigFile(configPath);
2226
+ const userConfig = await loadConfigFile(configPath, opts);
2221
2227
  const normalized = normalizeConfig(userConfig);
2222
2228
  const config = mergeConfig(normalized);
2223
2229
  return { config, configPath };