From 56de00b295657a71127b1682ae822c93fbc1db3f Mon Sep 17 00:00:00 2001 From: Maximo Mussini Date: Tue, 16 Mar 2021 18:37:34 -0300 Subject: [PATCH] feat: Allow passing a root option that is different than Vite's root --- src/index.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7303513..4a023a8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,6 +11,14 @@ function getShortName(file: string, root: string) { /** Plugin configuration */ interface Config extends WatchOptions { log?: boolean + + /** + * File paths will be resolved against this directory. + * + * @default ViteDevServer.root + * @internal + */ + root?: string } /** @@ -25,7 +33,9 @@ export default ( ): Plugin => ({ name: 'vite-plugin-live-reload', - configureServer({ ws, config: { root, logger } }: ViteDevServer) { + configureServer({ ws, config: { root: viteRoot, logger } }: ViteDevServer) { + const root = config.root || viteRoot + const reload = (path: string) => { ws.send({ type: 'full-reload', path }) if (config.log ?? true) { @@ -41,4 +51,4 @@ export default ( .on('add', reload) .on('change', reload) } -}) \ No newline at end of file +})