Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): bundle files referenced with imports field #18887

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,7 @@ async function bundleConfigFile(

// externalize bare imports
build.onResolve(
{ filter: /^[^.].*/ },
{ filter: /^[^.#].*/ },
async ({ path: id, importer, kind }) => {
Copy link
Member Author

@sapphi-red sapphi-red Dec 5, 2024

Choose a reason for hiding this comment

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

resolveByViteResolver uses tryNodeResolve and tryNodeResolve does not resolve imports fields. Resolving imports field in resolveByViteResolver can also fix the reported issue. But typescript files referenced by imports field doesn't work with that fix (I guess this didn't work from before though). I made imports field to be bundled instead to allow typescript files to be referenced by imports field.

if (
kind === 'entry-point' ||
Expand Down
1 change: 1 addition & 0 deletions playground/config/__tests__/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ it('loadConfigFromFile', async () => {
4,
],
],
"importsField": "imports-field",
"moduleCondition": "import condition",
}
`)
Expand Down
1 change: 1 addition & 0 deletions playground/config/packages/entry/imports-field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'imports-field'
3 changes: 3 additions & 0 deletions playground/config/packages/entry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"type": "module",
"dependencies": {
"@vite/test-config-plugin-module-condition": "link:../plugin-module-condition"
},
"imports": {
"#imports-field": "./imports-field.ts"
}
}
2 changes: 2 additions & 0 deletions playground/config/packages/entry/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import moduleCondition from '@vite/test-config-plugin-module-condition'
import { array } from '../siblings/foo'
import importsField from '#imports-field'

export default {
array,
moduleCondition,
importsField,
}
Loading