Skip to content

Commit

Permalink
feat: support rsbuild modify config hook
Browse files Browse the repository at this point in the history
  • Loading branch information
caohuilin committed Feb 18, 2025
1 parent 3903cf9 commit 3a9801f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/strange-rings-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/app-tools': minor
---

feat: support rsbuild modify config hook

feat: 支持 rsbuild 修改配置的 Hook 函数
2 changes: 2 additions & 0 deletions packages/solutions/app-tools/src/builder/generator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ async function applyBuilderPlugins<B extends Bundler>(
builderPluginAdapterBasic,
builderPluginAdapterHtml,
builderPluginAdapterSSR,
builderPluginAdapterHooks,
} = await import('../shared/builderPlugins/index.js');

builder.addPlugins([
builderPluginAdapterBasic(),
builderPluginAdapterSSR(options),
builderPluginAdapterHtml(options),
builderPluginAdapterHooks(options),
]);

builder.addPlugins([builderPluginAdapterCopy(options)], {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { RsbuildPlugin } from '@rsbuild/core';
import type { Bundler } from '../../../types';
import type { BuilderOptions } from '../types';

export const builderPluginAdapterHooks = <B extends Bundler>(
options: BuilderOptions<B>,
): RsbuildPlugin => ({
name: 'builder-plugin-support-modern-hooks',
setup(api) {
const _internalContext = options.appContext._internalContext;
const hooks = _internalContext.pluginAPI?.getHooks();
api.modifyBundlerChain(async (chain, utils) => {
await hooks?.modifyBundlerChain.call(chain, utils);
});
api.modifyRsbuildConfig(async (config, utils) => {
await hooks?.modifyRsbuildConfig.call(config, utils);
});
api.modifyRspackConfig(async (config, utils) => {
await hooks?.modifyRspackConfig.call(config, utils);
});
api.modifyWebpackChain(async (chain, utils) => {
await hooks?.modifyWebpackChain.call(chain, utils);
});
api.modifyWebpackConfig(async (config, utils) => {
await hooks?.modifyWebpackConfig.call(config, utils);
});
},
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './adapterBasic';
export * from './adapterHtml';
export * from './adapterSSR';
export * from './builderHooks';

0 comments on commit 3a9801f

Please sign in to comment.