1.0.0 • Published 3 years ago

vite-plugin-watch-lazy-folder v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

A plugin for vite-app to watch lazy folder and trigge update

Use Case

When you have some code like this for auto import all modules in folder;

//src/views/lazy/index.js
const modules = import.meta.glob('./*.jsx')

or

//src/store/index.js
const modules = import.meta.globEager('./*.js');

You may notice, in the lazy folder, add new file while you developing. Vite update will not trigge,becuase the new file isn't in the watch list;

Install

yarn add vite-plugin-watch-lazy-folder -D

or

npm i vite-plugin-watch-lazy-folder -D

Usage

import { defineConfig } from 'vite';
import watchLazyFolder from 'vite-plugin-watch-lazy-folder';

export default defineConfig({
  plugins: [
    watchLazyFolder([
      {
        folder: './src/views/lazy',
        triggeFile: 'index.js',
      },
    ]),
  ],

The parameter is WatchConfig[]

interface WatchConfig {
  /**The folder you wanna watch */
  folder: string;

  /**
   *  The file to trigge HMR;
   *  Would be resolve to  $folder/index.js;
   *  If undefined, will trigger restart;
   */
  triggeFile?: string;
}