cyco130 / vavite

Develop server-side applications with Vite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Works for transpilation, but what about bundling?

thomasjm opened this issue · comments

I set up vavite and it's working in development, but when I build for production, the server entry point dist/server/index.mjs contains externalized imports like import express from "express". These imports don't work unless I include an extra node_modules in production with the production dependencies.

But I really don't want to do this, because this node_modules folder would take tens of megabytes of extra space.

I'm migrating this app from a Webpack setup, where the index.ts file is bundled just like any other entry point, so the production dependencies are built in and optimized, tree-shaken etc.

Is there a way to accomplish the same thing with vavite?

Hi!

This is more or less a duplicate of this issue. You can find a few solution ideas there but they're out of scope for this project. In summary, you can try either bundling with ESBuild or only picking necessary files with @vercel/nft but some packages (notably Express!) require node_modules to be available so your mileage may vary.

Like I said, it's out of scope.

some packages (notably Express!) require node_modules to be available

I do not think that's true...I've been bundling Express applications using Webpack for years. I've also figured out how to do it with Vite in my current project.

I ended up switching to Vike for this and other reasons, but FWIW this seems like a natural thing for vavite to support. Especially as it seems like you can do it just by passing a few Rollup options.

You can simply pass those options in your Vite config.