-
Notifications
You must be signed in to change notification settings - Fork 47
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
Proposal: Simpler way to bundle Node apps with Vite #87
Comments
Wow, this is perfect! I've been fighting with those issues for quite a while before noticing this, it simply works. I'll try to think about a PR |
@srmagura, I tried your solution to build first and start the application, but it doesn't work. I have a demo here nestjs-vite-demo. When run the Nestjs with vite.pnpm run start:vite You can see below in the terminal. The server works. However, the socket doesn't work in this way. When you build and start the applicationpnpm run build:vite
pnpm run start:prod:vite We can only see the information below in the terminal. |
This is great. Thanks! |
Thank you for this library. It works well until you try to add WebSockets to your application. To fix this problem, I propose that we either create a new major version of vite-plugin-node or (more likely) create a new library that borrows some from vite-plugin-node.
Downsides to vite-plugin-node
The simpler way
All of the above issues stem from vite-plugin-node being intertwined with your Node application at runtime. We can fix all of the above by using Vite as a build tool only.
High-level steps when running your application in development:
vite build --mode development --watch
. It createsdist/main.js
when the initial compilation finishes.node dist/main.js
main.js
. This should trigger the application to restart. (You can use nodemon)Rough implementation
Here is an unpolished implementation of the above strategy.
start
script inpackage.json
:wait-for-build.mjs
:To use this, you'll need to run:
npm install --save-dev rimraf concurrently nodemon chokidar
Idea for cleaner implementation
The idea is to package the above "rough implementation" into a library. I think the library would have a CLI tool, and maybe a Vite plugin based off of vite-plugin-node. I would be interested in creating such a library if other people think they would use it.
The text was updated successfully, but these errors were encountered: