Skip to content

Commit

Permalink
chore: skip sideeffects set for HTML scripts for now
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Nov 6, 2024
1 parent fecb020 commit df2ddf0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
28 changes: 15 additions & 13 deletions packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,19 +489,21 @@ export function buildHtmlPlugin(config: ResolvedConfig): RolldownPlugin {
if (isModule) {
inlineModuleIndex++
if (url && !isExcludedUrl(url) && !isPublicFile) {
setModuleSideEffectPromises.push(
this.resolve(url, id)
.then((resolved) => {
if (!resolved) {
return Promise.reject()
}
return this.load(resolved)
})
.then((mod) => {
// set this to keep the module even if `treeshake.moduleSideEffects=false` is set
mod.moduleSideEffects = true
}),
)
// FIXME: rolldown does not support `this.load`: https://github.com/rolldown/rolldown/issues/2355
// setModuleSideEffectPromises.push(
// this.resolve(url, id)
// .then((resolved) => {
// if (!resolved) {
// return Promise.reject()
// }
// return this.load(resolved)
// })
// .then((mod) => {
// // set this to keep the module even if `treeshake.moduleSideEffects=false` is set
// mod.moduleSideEffects = true
// }),
// )

// <script type="module" src="..."/>
// add it as an import
js += `\nimport ${JSON.stringify(url)}`
Expand Down
2 changes: 1 addition & 1 deletion playground/html/__tests__/html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ describe('side-effects', () => {
await page.goto(viteTestUrl + '/side-effects/')
})

test('console.log is not tree-shaken', async () => {
test.skip('console.log is not tree-shaken', async () => {
expect(browserLogs).toContain('message from sideEffects script')
})
})
Expand Down

0 comments on commit df2ddf0

Please sign in to comment.