Skip to content

Watching public folder for changes & added files #153

Answered by james0r
james0r asked this question in Q&A
Discussion options

You must be logged in to vote

I got it working using a chokidar and a custom vite plugin

import fs from 'fs';
import path from 'path';
import chokidar from 'chokidar';

// Utility function to copy a file
function copyFile(src, dest) {
  fs.mkdirSync(path.dirname(dest), { recursive: true });
  fs.copyFileSync(src, dest);
}

// Utility function to remove a file
function removeFile(dest) {
  if (fs.existsSync(dest)) {
    fs.unlinkSync(dest);
  }
}

function copyPublicToAssetsPlugin() {
  let config;

  return {
    name: 'vite-plugin-copy-public',
    apply: 'serve', // Only apply this during development
    configResolved(resolvedConfig) {
      // Save the resolved Vite config
      config = resolvedConfig;
    },
    b…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by james0r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant