Giter Site home page Giter Site logo

Comments (8)

sync avatar sync commented on April 30, 2024 2

nice, have a look at this PR: #78

from fastify-vite.

bskimball avatar bskimball commented on April 30, 2024 1

Upgrading to 3.0.0-beta.21 worked for me. Thanks for the quick fix.

from fastify-vite.

sync avatar sync commented on April 30, 2024

New version does hmr, just tested it with React

from fastify-vite.

bskimball avatar bskimball commented on April 30, 2024

I get this with Vue ReferenceError: __VUE_HMR_RUNTIME__ is not defined

from fastify-vite.

sync avatar sync commented on April 30, 2024

I think the vite config is not properly passed trough so it's always building for prod,

here is my patch that made hmr work (in react):
fastify-vite+3.0.0-beta.20.patch.zip

you can use patch-package and drop this file into a patches folder in the root

diff --git a/node_modules/fastify-vite/config.js b/node_modules/fastify-vite/config.js
index 55bfdde..152c913 100644
--- a/node_modules/fastify-vite/config.js
+++ b/node_modules/fastify-vite/config.js
@@ -3,6 +3,7 @@ const { fileURLToPath } = require('url')
 const { dirname, join, resolve, exists, stat, read } = require('./ioutils')
 const { createHtmlTemplateFunction } = require('./html')
 
+
 const DefaultConfig = {
   // Whether or not to enable Vite's Dev Server
   dev: process.argv.includes('--dev'),
@@ -80,19 +81,21 @@ const DefaultConfig = {
     return (error, req, reply) => {
       if (config.dev) {
         console.error(error)
+        scope.vite.devServer.ssrFixStacktrace(error)
       }
-      scope.vite.devServer.ssrFixStacktrace(error)
       scope.errorHandler(error, req, reply)
     }
   },
 }
 
 async function configure (options = {}) {
-  const defaultConfig = Object.create(DefaultConfig)
+  const defaultConfig = {...DefaultConfig}
   const root = resolveRoot(options.root)
-  const [vite, viteConfig] = await resolveViteConfig(root)
+  const dev = typeof options.dev === 'boolean' ? options.dev : defaultConfig.dev;
+
+  const [vite, viteConfig] = await resolveViteConfig(root, dev)
   const clientModule = defaultConfig.clientModule ?? resolveClientModule(vite.root)
-  const bundle = await resolveBundle({ ...options, vite })
+  const bundle = await resolveBundle({ dev, vite })
   const config = Object.assign(defaultConfig, {
     ...options,
     vite,
@@ -136,12 +139,12 @@ function resolveRoot (root) {
   }
 }
 
-async function resolveViteConfig (root) {
+async function resolveViteConfig (root, dev) {
   for (const ext of ['js', 'mjs', 'ts', 'cjs']) {
     const configFile = join(root, `vite.config.${ext}`)
     if (exists(configFile)) {
       return [
-        await resolveConfig({ configFile }, 'build', 'production'),
+        await resolveConfig({ configFile }, 'build', dev ? 'development' : 'production'),
         configFile,
       ]
     }

from fastify-vite.

sync avatar sync commented on April 30, 2024

@galvez let me know if you would like a PR with those changes

from fastify-vite.

galvez avatar galvez commented on April 30, 2024

@sync Oh, that is a good catch! Would love a PR, for sure!

from fastify-vite.

galvez avatar galvez commented on April 30, 2024

Closed via #78

from fastify-vite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.