feat(core)!: refine bundler options#1714
Conversation
Coverage Report for CI Build 30002162063Coverage remained the same at 73.154%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
Co-authored-by: Mister-Hope <mister-hope@outlook.com>
Co-authored-by: Mister-Hope <mister-hope@outlook.com>
BREAKING CHANGE: core - |
There was a problem hiding this comment.
Pull request overview
This PR refines VuePress bundler configuration ergonomics for plugin authors by introducing a stable bundler discriminator (bundler.type) and changing the configureWebpack / configureVite hooks to support full config replacement (enabling array item removal), while also exposing bundler-specific merge utilities from bundler packages.
Changes:
- Add
Bundler.typeand migrate core logic to use it instead of comparingbundler.name. - Change
configureWebpackand introduceconfigureViteto allow returning a full config that replaces the generated config. - Re-export bundler merge helpers (
webpackMergeConfig,viteMergeConfig) from the bundler packages.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/tests/app/resolveAppOptions.spec.ts | Updates app-options test fixture to include new bundler.type. |
| packages/core/src/types/bundler.ts | Extends the Bundler interface with a new type discriminator. |
| packages/core/src/app/resolveAppMarkdown.ts | Switches bundler detection from bundler.name to bundler.type. |
| packages/bundler-webpack/src/webpackBundler.ts | Sets webpack bundler type: 'webpack'. |
| packages/bundler-webpack/src/types.ts | Updates configureWebpack documentation for new behavior. |
| packages/bundler-webpack/src/resolveWebpackConfig.ts | Changes configureWebpack return behavior to replace (not merge) webpack config. |
| packages/bundler-webpack/src/index.ts | Re-exports webpack-merge as webpackMergeConfig. |
| packages/bundler-vite/src/viteBundler.ts | Sets vite bundler type: 'vite'. |
| packages/bundler-vite/src/types.ts | Adds configureVite option for post-resolution Vite config modification/replacement. |
| packages/bundler-vite/src/resolveViteConfig.ts | Implements configureVite handling with replacement-on-return behavior. |
| packages/bundler-vite/src/index.ts | Re-exports Vite mergeConfig as viteMergeConfig. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Refine the
Bundlerinterface and bundler configuration hooks to give plugin authors the tools they need to configure bundler-specific behavior correctly and completely.Problems & Rationale
1. Complex comparison to identify the active bundler
Plugins in
extendsBundlerOptionsneed to know which bundler is active to add the right options (e.g.viteOptionsvschainWebpack). The only discriminator wasbundler.name, which is the full scoped package name.2. Missing merge helper in
extendsBundlerOptionsWhen a plugin accepts user bundler options and wants to merge them into the resolved options, it needs the correct merge function (
vite.mergeConfigvswebpack-mergediffer in semantics). The hook only passes(options, app)— no merge helper.We considered adding
mergeConfigas a hook parameter, but allextends*hooks share the uniform signature(extendable: T, app: App):Adding a third parameter would break this consistency. So
mergeConfigis exposed on theBundlerobject instead:export interface Bundler { name: string + type: string dev: (app: App) => Promise<() => Promise<void>> build: (app: App) => Promise<void> + mergeConfig: <Config extends Record<string, any>>( + currentConfig: Config, + newConfig: DeepPartial<Config>, + ) => Config }Plugins access it naturally:
app.options.bundler.mergeConfig(...).3.
configureWebpack/configureVitecannot remove array itemsThe old merge-on-return model was purely additive — array items could only be appended, never deleted.
Returning a value now fully replaces the config.
To merge explicitly, use themergeConfigcallback parameter passed to the hook.Note: the
mergeConfigfrom vite always create a fresh new object at every level while merging.Breaking changes
Bundlerinterface now requirestypeandmergeConfig.configureWebpackreturn value replaces the config. Use the passedmergeConfigparameter to merge instead.