Skip to content

Commit 821298c

Browse files
committed
Enhance auto-import feature by specifying TypeScript definition and ESLint configuration file paths. Improve Webpack integration to support plugin appending in rspack configuration.
1 parent 95d244a commit 821298c

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/features/autoImport/autoImport.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ export default (api: IApi) => {
5858

5959
return {
6060
imports,
61-
dts: true,
61+
dts: './auto-imports.d.ts',
6262
eslintrc: {
6363
enabled: true,
64+
filepath: './.eslintrc-auto-import.json',
6465
},
6566
};
6667
};
@@ -81,17 +82,25 @@ export default (api: IApi) => {
8182
// Rsbuild 集成 (基于 Rspack)
8283
api.modifyRsbuildConfig((config: any) => {
8384
config.tools = config.tools || {};
84-
const originalRspack = config.tools.rspack;
85-
86-
config.tools.rspack = (rspackCfg: any) => {
87-
const cfg =
88-
typeof originalRspack === 'function'
89-
? originalRspack(rspackCfg)
90-
: originalRspack || rspackCfg;
91-
cfg.plugins = cfg.plugins || [];
92-
cfg.plugins.push(AutoImportRspack(getAutoImportConfig()));
93-
return cfg;
85+
86+
// 保存之前的配置函数
87+
const prevRspack = config.tools.rspack;
88+
89+
config.tools.rspack = (rspackConfig: any, context: any) => {
90+
// 先执行之前的配置(如果存在)
91+
let resultConfig = rspackConfig;
92+
if (typeof prevRspack === 'function') {
93+
resultConfig = prevRspack(rspackConfig, context);
94+
}
95+
96+
// 使用 appendPlugins 添加插件
97+
if (context && context.appendPlugins) {
98+
context.appendPlugins(AutoImportRspack(getAutoImportConfig()));
99+
}
100+
101+
return resultConfig;
94102
};
103+
95104
return config;
96105
});
97106
};

0 commit comments

Comments
 (0)