Revert no bundling approach#1479
Conversation
|
📝 WalkthroughWalkthroughThe build pipeline for autocomplete-client and instant-meilisearch packages is updated to run Vite bundling before TypeScript compilation. TypeScript configurations are modified to emit only type declarations while source maps are disabled in tsc, delegating the primary build work to Vite with proper library mode and ES module output configuration. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/autocomplete-client/package.json`:
- Line 7: The package lists `@meilisearch/instant-meilisearch` as a regular
dependency which causes Vite library mode to inline its source into the built
bundle; either move "@meilisearch/instant-meilisearch" from dependencies to
peerDependencies in packages/autocomplete-client/package.json or modify the
library build config (vite.config.ts) for the autocomplete-client target to add
rollupOptions.external including "@meilisearch/instant-meilisearch" so Rollup
treats it as external; update package.json and/or vite.config.ts (look for the
build script and the vite config entry for this package and the
rollupOptions.external setting) and publish with the dependency externalized to
avoid bundling duplicate copies.
In `@packages/autocomplete-client/vite.config.ts`:
- Around line 6-14: The build currently inlines dependencies because Vite only
externals peerDependencies; update the build configuration inside the existing
build block (the same block containing lib.entry and fileName) to add
rollupOptions.external that explicitly externalizes
'@meilisearch/instant-meilisearch' and 'meilisearch' (use exact names and/or a
regex to catch subpath imports) so the Rollup bundler will not inline their
source into dist/index.js; ensure you update the build.rollupOptions.external
array in vite.config.ts accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: bfb5e4df-9f2d-4419-9698-af0df0e0a5f5
📒 Files selected for processing (6)
packages/autocomplete-client/package.jsonpackages/autocomplete-client/tsconfig.jsonpackages/autocomplete-client/vite.config.tspackages/instant-meilisearch/package.jsonpackages/instant-meilisearch/tsconfig.jsonpackages/instant-meilisearch/vite.config.ts
| "homepage": "https://github.com/meilisearch/meilisearch-js-plugins/tree/main/packages/autocomplete-client", | ||
| "scripts": { | ||
| "build": "tsc" | ||
| "build": "vite build && tsc" |
There was a problem hiding this comment.
Build pipeline OK; see vite.config.ts for an externals concern that affects this published bundle.
The script itself is correct, but autocomplete-client has @meilisearch/instant-meilisearch as a regular dependency. Vite library mode only externalizes peerDependencies by default, so without explicit rollupOptions.external the workspace instant-meilisearch source (its exports resolves to ./src/index.ts) will be inlined into this package's dist/index.js. Consumers installing both packages would ship two copies. See the vite.config.ts comment for the suggested fix.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/autocomplete-client/package.json` at line 7, The package lists
`@meilisearch/instant-meilisearch` as a regular dependency which causes Vite
library mode to inline its source into the built bundle; either move
"@meilisearch/instant-meilisearch" from dependencies to peerDependencies in
packages/autocomplete-client/package.json or modify the library build config
(vite.config.ts) for the autocomplete-client target to add
rollupOptions.external including "@meilisearch/instant-meilisearch" so Rollup
treats it as external; update package.json and/or vite.config.ts (look for the
build script and the vite config entry for this package and the
rollupOptions.external setting) and publish with the dependency externalized to
avoid bundling duplicate copies.
| build: { | ||
| sourcemap: true, | ||
| target: tsconfig.compilerOptions.target, | ||
| lib: { | ||
| entry: 'src/index.ts', | ||
| formats: ['es'], | ||
| fileName: 'index', | ||
| }, | ||
| }, |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Vite library mode externalize regular dependencies default behavior
💡 Result:
In Vite's library mode (enabled via build.lib), regular dependencies are bundled into the library output by default. Vite does not automatically externalize them. To externalize dependencies (prevent bundling), explicitly configure build.rollupOptions.external with the dependency names, typically loaded from package.json dependencies: import pkg from './package.json' export default defineConfig({ build: { lib: { /* ... */ }, rollupOptions: { external: Object.keys(pkg.dependencies || {}) } } }) Official Vite docs recommend manually externalizing deps you do not want bundled, e.g., React/Vue. Examples in docs show empty { rollupOptions: {} } or explicit externals like ['vue']. Community discussions confirm no auto-externalization; plugins like vite-plugin-externalize-deps exist as workarounds. Source code shows rollupOptions.external used directly if provided, otherwise undefined (bundles deps). This behavior persists as of 2026.
Citations:
- 1: https://vite.dev/guide/build
- 2: https://vite.dev/config/build-options
- 3: https://vite.dev/config/
- 4: Library mode: How should I manage external dependencies? vitejs/vite#6198
- 5: https://stackoverflow.com/questions/70433387/library-mode-in-vitejs-how-should-i-manage-external-dependencies
- 6: https://cmdcolin.github.io/posts/2025-02-23-vitelibrarymode/
- 7: https://readmedium.com/using-vite-in-library-mode-ce2d352c6c3f
- 8: Automatically use `package.json`'s dependencies for `rollupOptions.external` when in `lib` mode vitejs/vite#10582
🏁 Script executed:
# Check the package.json to see dependency classification
cat packages/autocomplete-client/package.json | grep -A 20 '"dependencies"' | head -15Repository: meilisearch/meilisearch-js-plugins
Length of output: 217
🏁 Script executed:
# Check the current vite.config.ts file
cat packages/autocomplete-client/vite.config.tsRepository: meilisearch/meilisearch-js-plugins
Length of output: 533
Externalize @meilisearch/instant-meilisearch (and meilisearch) explicitly.
In library mode Vite externalizes only peerDependencies. Since @meilisearch/instant-meilisearch is listed under dependencies and its workspace exports map resolves . to ./src/index.ts, Vite will inline its entire source tree into this package's dist/index.js. End users that also install @meilisearch/instant-meilisearch (which is the typical case) would then get two divergent copies and a larger bundle. Declaring it (and the meilisearch peer, for safety/regex coverage) as external avoids that.
♻️ Proposed fix
export default defineConfig({
build: {
sourcemap: true,
target: tsconfig.compilerOptions.target,
lib: {
entry: 'src/index.ts',
formats: ['es'],
fileName: 'index',
},
+ rollupOptions: {
+ external: [/^@meilisearch\/instant-meilisearch(\/|$)/, /^meilisearch(\/|$)/],
+ },
},📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| build: { | |
| sourcemap: true, | |
| target: tsconfig.compilerOptions.target, | |
| lib: { | |
| entry: 'src/index.ts', | |
| formats: ['es'], | |
| fileName: 'index', | |
| }, | |
| }, | |
| build: { | |
| sourcemap: true, | |
| target: tsconfig.compilerOptions.target, | |
| lib: { | |
| entry: 'src/index.ts', | |
| formats: ['es'], | |
| fileName: 'index', | |
| }, | |
| rollupOptions: { | |
| external: [/^@meilisearch\/instant-meilisearch(\/|$)/, /^meilisearch(\/|$)/], | |
| }, | |
| }, |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/autocomplete-client/vite.config.ts` around lines 6 - 14, The build
currently inlines dependencies because Vite only externals peerDependencies;
update the build configuration inside the existing build block (the same block
containing lib.entry and fileName) to add rollupOptions.external that explicitly
externalizes '@meilisearch/instant-meilisearch' and 'meilisearch' (use exact
names and/or a regex to catch subpath imports) so the Rollup bundler will not
inline their source into dist/index.js; ensure you update the
build.rollupOptions.external array in vite.config.ts accordingly.
There was a problem hiding this comment.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
Pull Request
Related issue
Fixes #1478
What does this PR do?
PR checklist
Please check if your PR fulfills the following requirements:
Thank you so much for contributing to Meilisearch!
Summary by CodeRabbit