Code Monkey home page Code Monkey logo

vite-plugin-full-reload's Introduction

vite-plugin-full-reload

Automatically reload the page when files are modified


Why? 🤔

When using Vite Ruby, I wanted to see changes to server-rendered layouts and templates without having to manually reload the page.

Also, in JS From Routes path helpers are generated when Rails reload is triggered.

Triggering a page reload when config/routes.rb is modified makes the DX very smooth.

Installation 💿

Install the package as a development dependency:

npm i -D vite-plugin-full-reload # yarn add -D vite-plugin-full-reload

Usage 🚀

Add it to your plugins in vite.config.ts

import { defineConfig } from 'vite'
import FullReload from 'vite-plugin-full-reload'

export default defineConfig({
  plugins: [
    FullReload(['config/routes.rb', 'app/views/**/*'])
  ],
})

This is useful to trigger a page refresh for files that are not being imported, such as server-rendered templates.

To see which file globbing options are available, check picomatch.

Configuration ⚙️

The following options can be provided:

  • root

    Files will be resolved against this directory.

    Default: process.cwd()

    FullReload('config/routes.rb', { root: __dirname }),
  • delay

    How many milliseconds to wait before reloading the page after a file change. It can be used to offset slow template compilation in Rails.

    Default: 0

    FullReload('app/views/**/*', { delay: 100 })
  • always

    Whether to refresh the page even if the modified HTML file is not currently being displayed.

    Default: true

    FullReload('app/views/**/*', { always: false })

Acknowledgements

  • vite-plugin-live-reload

    This is a nice plugin, I found it right before publishing this one.

    I've made two PRs that were needed to support these use cases.

    At this point in time they are very similar, except this library doesn't create another chokidar watcher.

License

This library is available as open source under the terms of the MIT License.

vite-plugin-full-reload's People

Contributors

elmassimo avatar mikemand avatar timacdonald avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vite-plugin-full-reload's Issues

Slim template

hello, does this library work with slim template ?

Possible to work in lib mode?

Like the title says, I've tried using this in lib mode, however it doesn't trigger a reload like it does in normal mode.

Is this possible to do?

Vite 5 support

 WARN  Issues with peer dependencies found
└─┬ vite-plugin-full-reload 1.0.5
└── ✕ unmet peer vite@"^2 || ^3 || ^4": found 5.0.0

Proxy mode

I run Vite as proxy of built-in php server:

import {defineConfig} from 'vite';
import fullReload from 'vite-plugin-full-reload';

export default defineConfig({
    server: {
        proxy: {
            '/': 'http://localhost:8080'
        }
    },
    plugins: [
        fullReload('*.php')
    ],
});

The problem: when I update PHP file, I see «page reload» message in the terminal, but no page reload happens.

doesn't seem to work

Hi i'm trying to use this useful plugin but i cant get it to work as expected
heres how i configured vite config

plugins:   [
    FullReload([
      'packages/reader/src/hooks/pdf-viewer/viewer-setup.ts',
      'packages/reader/src/hooks/pdf-viewer/settings-change.ts',
      'packages/reader/src/hooks/pdf-viewer/page-change.ts',
      'packages/reader/src/hooks/pdf-viewer/context-menu.ts',
      'packages/reader/src/hooks/pdf-viewer/viewer-setup/callbacks.ts',
      'packages/reader/src/hooks/pdf-viewer/viewer-setup/presets.ts',
      'packages/reader/src/hooks/pdf-viewer/viewer-setup/toolbars.ts',
      'packages/reader/src/components/pdf-viewer.tsx'
    ], { log: true, always: true }),
    checker({
      typescript: true
    }),
    react()
  ]

once i edit for example packages/reader/src/hooks/pdf-viewer/viewer-setup.ts i expect to the full reload but nothing happens except HMR that kicks in
heres the vite terminal log

6:18:00 PM [vite] ../../vite.config.ts changed, restarting server...
6:18:00 PM [vite] server restarted.
[TypeScript] Found 0 errors. Watching for file changes.
6:19:10 PM [vite] hmr update /@fs/Users/majklzumberi/Documenti/github/books/packages/ui/styles/index.css, /@fs/Users/majklzumberi/Documenti/github/books/packages/reader/src/components/pdf-viewer.tsx
[TypeScript] Found 0 errors. Watching for file changes.
6:21:53 PM [vite] hmr update /@fs/Users/majklzumberi/Documenti/github/books/packages/ui/styles/index.css, /@fs/Users/majklzumberi/Documenti/github/books/packages/reader/src/components/pdf-viewer.tsx
[TypeScript] Found 0 errors. Watching for file changes.

i see that pdf-viewer.tsx changes (this file include as hook the viewer.setup one), i tried to include pdf-viewer.tsx in the list but still nothing changes.

Where i'm doing wrong?

Specifying Path to point to /src

Hello! Great plugin - thank so much for implementing this.

I'm currently running a Vue3 app & I'm trying to have the app fully reload upon any edits to all Vue components in my views folder:

Is this the proper configuration?

FullReload(['views/**/*.*', 'src/'])

Vite 5 warning - The CJS build of Vite's Node API is deprecated

I get the following warning on vite 5 which traces back to this plugin, see trace below. The warning references https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.

Trace: The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
    at warnCjsUsage (/Users/tvongaza/aeon/aeonv2/node_modules/vite/index.cjs:32:3)
    at Object.<anonymous> (/Users/tvongaza/aeon/aeonv2/node_modules/vite/index.cjs:3:1)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at _require.extensions.<computed> [as .js] (file:///Users/tvongaza/aeon/aeonv2/node_modules/vitest/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:66343:17)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Module.require (node:internal/modules/cjs/loader:1115:19)
    at require (node:internal/modules/helpers:130:18)
    at Object.<anonymous> (/Users/tvongaza/aeon/aeonv2/node_modules/vite-plugin-full-reload/dist/index.cjs:5:13)

Choose path to refresh

I'd love to have a feature to have a certain path to refresh on a specific changed file.

E.g. I use the plugin with a CMS that stores its content and configuration in txt & yaml files.

  • When that content changes, I want to reload all pages but not the CMS panel
  • When configuration changes, I want to reload only the panel pages

Paths to refresh could also be defined via glob matching.

Example configuration:

  plugins: [
    FullReload([
      {
        watch: ["site/{layouts,snippets,templates}/**/*", "content/**/*"],
        reload: ["!/panel", "*"]
      },
      {
        watch: ["site/blueprints/**/*"],
        reload: ["/panel"]
      }
    ])
  ],

Altering excluded files blocks Vite HMR

Great plugin thx! One issue made me move to vite-plugin-live-reload. When I set path to watch for only some extensons like 'src/**/*.ts' then altering other files, prevent Vite from hot reload that other files. I was testing this with .sccs files.

Page still reloads after removing the plugin

I've removed the plugin from 'vite.config.ts' but Vite is still reloading the page. My setup was to reload on changes to 'views', 'components', and 'routes.rb'. My current config is:

import { defineConfig } from "vite"
import RubyPlugin from "vite-plugin-ruby"
import StimulusHMR from "vite-plugin-stimulus-hmr"
import yaml from "@rollup/plugin-yaml"

export default defineConfig({
  build: {
    sourcemap: false,
  },
  plugins: [yaml(), RubyPlugin(), StimulusHMR()],
})

I restarted my machine and reinstalled Vite + plugins, but no luck.

Could anyone help with that? Thank you

Vite 5 support

 WARN  Issues with peer dependencies found
└─┬ vite-plugin-full-reload 1.0.5
└── ✕ unmet peer vite@"^2 || ^3 || ^4": found 5.0.0

Vite 5 support

 WARN  Issues with peer dependencies found
└─┬ vite-plugin-full-reload 1.0.5
└── ✕ unmet peer vite@"^2 || ^3 || ^4": found 5.0.0

Bug when first argument is a string instead of an array of strings

Works:

fullReloadPlugin(['dir/*.php'])

Breaks:

fullReloadPlugin('dir/*.php')

The argument is passed to Array.from, so dir/*.php is turned into ['d', 'i', 'r', '/', '*', ...]! Now all of these are watched as separate globs, including *, so lots of watcher processes are spawned, every single file in the project is watched and the development server slows to a crawl.

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.