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: ignore sideEffects for scripts imported from html #12786

Merged
Merged
Changes from 1 commit
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
19 changes: 12 additions & 7 deletions packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,19 +260,24 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin {
}

if ((res = tryFsResolve(fsPath, options))) {
const resPkg = findNearestPackageData(
path.dirname(res),
options.packageCache,
)
res = ensureVersionQuery(res, id, options, depsOptimizer)
debug?.(`[relative] ${colors.cyan(id)} -> ${colors.dim(res)}`)

return resPkg
? {
// If this isn't a script imported from a .html file, include side effects
// hints so the non-used code is properly tree-shaken during build time.
if (!importer?.endsWith('.html')) {
const resPkg = findNearestPackageData(
path.dirname(res),
options.packageCache,
)
if (resPkg) {
return {
id: res,
moduleSideEffects: resPkg.hasSideEffects(res),
}
: res
}
}
return res
}
}

Expand Down