Skip to content

Commit

Permalink
Merge pull request #3 from ElMassimo/root
Browse files Browse the repository at this point in the history
feat: Allow passing a root option that is different than Vite's root
  • Loading branch information
arnoson authored Mar 17, 2021
2 parents 67b834f + 56de00b commit 68ae561
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 68ae561

Please sign in to comment.