feat: support full bundle mode in ssr#21626
feat: support full bundle mode in ssr#21626sheremet-va wants to merge 22 commits intovitejs:mainfrom
Conversation
|
Very excited to see the beginnings of this! |
packages/vite/src/node/server/environments/fullBundleEnvironment.ts
Outdated
Show resolved
Hide resolved
| const href = posixPathToFileHref(modulePath) | ||
| const filename = modulePath | ||
| const dirname = posixDirname(modulePath) | ||
| const isVirtual = modulePath.startsWith('data:application/javascript,') |
There was a problem hiding this comment.
This is what Node returns in import.meta.url if it runs in REPL or inside --import=data/application. I think we can reuse this idea
import.meta.dirname and filename are also not available there since files are virtual
But it will be quite inconvenient at runtime
There was a problem hiding this comment.
Another idea is to use the file where it would be bundled. However then something like readFileSync(import.meta.filename) will throw an error
There was a problem hiding this comment.
I decided to go with the second approach for now to avoid any breaking changes
| dep = String(dep) | ||
| if (dep[0] === '.') { | ||
| dep = posixResolve(posixDirname(url), dep) | ||
| dep = posixJoin(posixDirname(url), dep) |
There was a problem hiding this comment.
resolve always adds process.cwd() at the start, but we are resolving ./file1.js relative to asset/parent.js
…he runner code to minimise copypaste
I am exploring how full bundle mode can be supported in SSR. At the moment the goal is to support
environments.ssr.runner.importandenvironment.fetchModule. Module graph,transformRequest,pluginContainerare out of scope of this PR, but they will be revisited later.Known quirks (to discuss)
runner.import(url)is not resolved withresolveIdlike it is done usually. Instead it accepts:rolldownOptions.input/(/entry-point.jsvs./entry-point.js)urlmust be an actual filename or a URL with the extension at the endimport.meta.url,import.meta.filenameandimport.meta.dirnamereference "would be" (or "virtual") files, these are the URLs that would exist if vite kept the bundle on the file system. Doing something likereadFileSync(import.meta.filename)will throw an error because the file does not exist on disk{ ourDir: './dist' }, the filename would be something like<root>/dist/asset/chunk-1.js