Skip to content
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

Transpile server code #562

Open
brillout opened this issue Dec 16, 2022 · 16 comments
Open

Transpile server code #562

brillout opened this issue Dec 16, 2022 · 16 comments

Comments

@brillout
Copy link
Member

brillout commented Dec 16, 2022

By default, your server code isn't processed by Vite:

// server/index.js

// This file isn't processed by Vite. Consequently:
//  - When changing this file, you needed to manually restart your server for your changes to take effect.
//  - To use your environment variables defined in your .env files, you need to install dotenv.
//    See: https://vite-plugin-ssr.com/env
//  - To use your path aliases defined in your vite.config.js, you need to tell Node.js about them.
//    See: https://vite-plugin-ssr.com/path-aliases

// Your server, for example an Express.js app
import express from 'express'
const app = express()

// ...

If you want Vite to process your server code then use one of these:

If you merely want to transpile TypeScript, you can use:

Instead of having to use an extra tool, vike should have a new option server: './path/to/server/entry.ts'.

Edit:

@brillout brillout added the enhancement ✨ New feature or request label Dec 16, 2022
@samuelstroschein
Copy link
Contributor

For context, this issue has been opened due to #560

@brillout
Copy link
Member Author

Quoting @nitedani.

How about including vavite in vps? As a new vps user, I would except vps to work with nodejs ssr out of the box, including hot-reloading server-side code.

I share the sentiment. Although, instead of including vavite in VPS, I currently have a slight preference for making the boilerplates use vavite. I understand that having to use a plethora of tools to get started isn't ideal – the goal in that regard is to build frameworks on top of VPS that are more opinionated and larger in scope.

That said, I'll have a closer look at vavite's code and if the hacks it uses don't have negative side effects, I'll consider integrating vavite into VPS. I'll have a look at it after I'm done with the V1 design.

@samuelstroschein
Copy link
Contributor

samuelstroschein commented Apr 9, 2023

Duplicate of #169 / close #169 in favor of this one ?

@brillout

This comment was marked as off-topic.

@brillout
Copy link
Member Author

brillout commented Apr 26, 2023

The plan long term was to use HatTip.

But, I'm starting to think that, regardless of HatTip, we still need this. Because we don't want to force users to use HatTip.

I've heard that there is some discussions to integrate vite-node into Vite. I'll see if I can find the disucssion.

@brillout
Copy link
Member Author

I'll see if I can find the disucssion.

vitejs/vite#12165 (comment).

@aheissenberger
Copy link

I use vavite and since the last changes in vitejs debugging backend (vise-plugin-ssr, trpc and express) with sourcemaps works with nodejs 18-20 without any node loader like a charm.

@brillout
Copy link
Member Author

brillout commented Jun 8, 2023

Also https://github.com/szymmis/vite-express. But it uses nodemon to watch server files for changes which comes with its own problems, and it doesn't seem to send Vite's full-reload HMR signal.

@brillout
Copy link
Member Author

Also https://github.com/egoist/vite-plugin-mix, and in particular @rhildred's interesting approach of using cloudflare2express with his fork https://github.com/diy-pwa/vite-plugin-mix.

@BanDroid

This comment was marked as off-topic.

@brillout

This comment was marked as off-topic.

@CertainlyAria

This comment was marked as off-topic.

@brillout

This comment was marked as off-topic.

@alessandrojcm
Copy link

Vite's experimental runtime api was just released in the latest beta, might give it a try in the next few days.

@brillout
Copy link
Member Author

brillout commented Feb 7, 2024

@alessandrojcm FYI we're also experimenting with it at #1342. It's looking promising. Exciting.

@brillout
Copy link
Member Author

brillout commented Mar 8, 2024

Vite is refactoring its Vite Runtime API design (which they're renaming Vite Environment API), see vitejs/vite#16089.

Rough release estimate:

@Blu proposed that we release 5.2 with what we currently have in the milestone, as implementing the new revised version will take some time. So we are aiming to release Environment API in 5.3 (removing Runtime API), and then do another cycle of feedback, and revise it for 5.4 (and hopefully there we can keep it experimental but stable). Then on Vite 6 we could make it stable, but keeping all current APIs backward compatible. Vite 7 if possible will remove the mixed server.moduleGraph

So it's going to take a while until we can finish implementing this. (Progress on Vike's side at PR #1513.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants