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 +})