mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 14:48:41 +00:00
fix(ssr): mark builtin modules as side effect free (#15658)
This commit is contained in:
parent
110e2e1651
commit
526cf23410
@ -407,7 +407,9 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin {
|
||||
this.error(message)
|
||||
}
|
||||
|
||||
return options.idOnly ? id : { id, external: true }
|
||||
return options.idOnly
|
||||
? id
|
||||
: { id, external: true, moduleSideEffects: false }
|
||||
} else {
|
||||
if (!asSrc) {
|
||||
debug?.(
|
||||
|
@ -25,3 +25,11 @@ test.runIf(isBuild)('correctly resolve entrypoints', async () => {
|
||||
|
||||
await expect(import(`${testDir}/dist/main.mjs`)).resolves.toBeTruthy()
|
||||
})
|
||||
|
||||
test.runIf(isBuild)(
|
||||
'node builtins should not be bundled if not used',
|
||||
async () => {
|
||||
const contents = readFile('dist/main.mjs')
|
||||
expect(contents).not.include(`node:url`)
|
||||
},
|
||||
)
|
||||
|
@ -6,6 +6,7 @@ import fileEntry from '@vitejs/test-entries/file'
|
||||
import pkgExportsEntry from '@vitejs/test-resolve-pkg-exports/entry'
|
||||
import deepFoo from '@vitejs/test-deep-import/foo'
|
||||
import deepBar from '@vitejs/test-deep-import/bar'
|
||||
import { used } from './util'
|
||||
|
||||
export default `
|
||||
entries/dir: ${dirEntry}
|
||||
@ -13,4 +14,5 @@ export default `
|
||||
pkg-exports/entry: ${pkgExportsEntry}
|
||||
deep-import/foo: ${deepFoo}
|
||||
deep-import/bar: ${deepBar}
|
||||
util: ${used(['[success]'])}
|
||||
`
|
||||
|
10
playground/ssr-resolve/util.js
Normal file
10
playground/ssr-resolve/util.js
Normal file
@ -0,0 +1,10 @@
|
||||
import { pathToFileURL } from 'node:url'
|
||||
|
||||
export function used(s) {
|
||||
return s
|
||||
}
|
||||
|
||||
// This is not used, so `node:url` should not be bundled
|
||||
export function treeshaken(s) {
|
||||
return pathToFileURL(s)
|
||||
}
|
Loading…
Reference in New Issue
Block a user