question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vite dev server: support netlify dev

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
ghostcommented, Mar 18, 2021

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"
  },
2reactions
riderxcommented, Nov 30, 2021

with lastest version each time we start the server a random port is used so it’s need to add functionsPort = 8885 in netlife dev config like below:

[build.environment]
  NPM_FLAGS = "--prefix=/dev/null"
  NODE_VERSION = "14"

[build]
  publish = "dist"
  command = "npx pnpm i --store=node_modules/.pnpm-store && npx pnpm run build"

[[redirects]]
  force = true
  from = '/api/*'
  status = 200
  to = '/.netlify/functions/:splat'

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

[[headers]]
  for = "/manifest.webmanifest"
  [headers.values]
    Content-Type = "application/manifest+json"

[dev]
  autoLaunch = false
  functionsPort = 8885

and vite config :

// 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:8885/.netlify/functions',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, ''),
      },
    },
  },
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Trouble setting up netlify dev with vite and npm monorepos
I'm trying to set up an npm monorepo for a large project that is logical to be broken down into its own packages:...
Read more >
Deploying a Static Site - Vite
Vite is installed as a local dev dependency in your project, ... Vite also supports Server Side Rendering. ... Azure DevOps). Import the...
Read more >
Developing with Vite - Vite Ruby
In this section, we'll cover the basics to get started with Vite in Ruby web apps. Development Server #. Run bin/vite dev to...
Read more >
Build and Deploy a Single Page App with React, Vite, and ...
This is a large undertaking, but it accurately describes the whole development cycle. The application will be deployed to Netlify.
Read more >
Set up Vite local dev with the Netlify CLI | egghead.io
In this lesson, you'll globally install the Netlify CLI and use its dev command to run your site locally. Netlify automatically detects if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found