-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Vite dev server: support netlify dev #2571
Comments
I use them together like this: # netlify.toml
[[redirects]]
force = true
from = '/api/*'
status = 200
to = '/.netlify/functions/:splat'
[[redirects]]
from = '/*'
status = 200
to = '/index.html'
[build]
command = 'npm run build'
environment = {NODE_VERSION = '14'}
publish = 'dist'
[dev]
autoLaunch = false // vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'@': path.resolve(__dirname, '/src'),
},
},
server: {
open: true,
proxy: {
'/api': {
target: 'http://localhost:8888/.netlify/functions',
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, ''),
},
},
},
}) Then run two commands: "scripts": {
"dev": "vite",
"netlify": "netlify dev",
"build": "vite build"
}, |
Thanks for the workaround! This works out of the box with vue-cli though. |
This was awesome and super helpful @web2033 . I had a strange problem after I updated netlify-cli from 3.13 to 3.28. I was getting the following error: ◈ "npm run build" exited with code 0. Shutting down Netlify Dev server I'm not really sure why this suddenly popped up when going from 3.13 - 3.28, but it was solved with the following change to netlify.toml and scripts [dev]
autoLaunch = false
command = "npm run dev" |
with lastest version each time we start the server a random port is used so it's need to add
and vite config :
|
I had to add
|
@nicooprat i forgot to update my message but yes your are right it’s needed |
Closing as |
Is your feature request related to a problem? Please describe.
netlify dev doesn't work with vite dev server. netlify dev starts a proxy server which redirect to vite dev server. However vite dev server replies with
ok
. I suspect this might be due to host mismatch, since the proxy and the server and on different ports.Describe the solution you'd like
vite dev server and netlify dev should be friends.
Describe alternatives you've considered
Checked the vite docs for a way to relax the hostname checking
Additional context
Reproduction repository: https://github.com/franciscolourenco/netlify-dev-vite
The text was updated successfully, but these errors were encountered: