Skip to content

Commit

Permalink
feat: warn when using Rspack devServer config (#4431)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Jan 25, 2025
1 parent 12c84a1 commit b45c195
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions packages/core/src/provider/rspackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,31 @@ export function getChainUtils(
};
}

function validateRspackConfig(config: Rspack.Configuration) {
// validate plugins
if (config.plugins) {
for (const plugin of config.plugins) {
if (
plugin &&
plugin.apply === undefined &&
'name' in plugin &&
'setup' in plugin
) {
const name = color.bold(color.yellow(plugin.name));
throw new Error(
`[rsbuild:plugin] "${name}" appears to be an Rsbuild plugin. It cannot be used as an Rspack plugin.`,
);
}
}
}

if (config.devServer) {
logger.warn(
`[rsbuild:config] Find invalid Rspack config: "${color.yellow('devServer')}". Note that Rspack's "devServer" config is not supported by Rsbuild. You can use Rsbuild's "dev" config to configure the Rsbuild dev server.`,
);
}
}

export async function generateRspackConfig({
target,
context,
Expand Down Expand Up @@ -160,22 +185,7 @@ export async function generateRspackConfig({
await getConfigUtils(rspackConfig, chainUtils),
);

// validate plugins
if (rspackConfig.plugins) {
for (const plugin of rspackConfig.plugins) {
if (
plugin &&
plugin.apply === undefined &&
'name' in plugin &&
'setup' in plugin
) {
const name = color.bold(color.yellow(plugin.name));
throw new Error(
`[rsbuild:plugin] "${name}" appears to be an Rsbuild plugin. It cannot be used as an Rspack plugin.`,
);
}
}
}
validateRspackConfig(rspackConfig);

return rspackConfig;
}

1 comment on commit b45c195

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
plugins ✅ success
rspress ✅ success
rslib ✅ success
examples ✅ success

Please sign in to comment.