Skip to content

Commit

Permalink
feat: Allow passing a root option that is different than Vite's root
Browse files Browse the repository at this point in the history
  • Loading branch information
ElMassimo committed Mar 16, 2021
1 parent 67b834f commit 56de00b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand All @@ -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) {
Expand All @@ -41,4 +51,4 @@ export default (
.on('add', reload)
.on('change', reload)
}
})
})

0 comments on commit 56de00b

Please sign in to comment.