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: only remove entry assets handled by Vite core #17916

Merged
merged 3 commits into from
Sep 1, 2024
Merged
Changes from 2 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
7 changes: 6 additions & 1 deletion packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
config.command === 'build' && this.getModuleInfo(id)?.isEntry
? 'no-treeshake'
: false,
meta:
config.command === 'build' && this.getModuleInfo(id)?.isEntry
? { 'vite:asset': true }
Copy link
Member

Choose a reason for hiding this comment

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

Should we name this 'vite:entry-asset'? Or maybe remove the isEntry condition and later on let other places use the 'vite:asset' meta info?
It may be confusing while debugging for people to see vite:asset only added for some assets handled by vite.

Copy link
Member Author

Choose a reason for hiding this comment

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

As a convention, the plugin name is used as a key name.
I'll remove the isEntry condition.

: undefined,
}
},

Expand All @@ -230,7 +234,8 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
chunk.type === 'chunk' &&
chunk.isEntry &&
chunk.moduleIds.length === 1 &&
config.assetsInclude(chunk.moduleIds[0])
config.assetsInclude(chunk.moduleIds[0]) &&
this.getModuleInfo(chunk.moduleIds[0])?.meta['vite:asset']
) {
delete bundle[file]
}
Expand Down