vite-plugin-live-reload
Advanced tools
Comparing version 2.0.0-beta.0 to 2.0.0
@@ -7,2 +7,3 @@ 'use strict'; | ||
var chalk = require('chalk'); | ||
var path = require('path'); | ||
@@ -13,14 +14,18 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk); | ||
var path__default = /*#__PURE__*/_interopDefaultLegacy(path); | ||
function getShortName(file, root) { | ||
return file.startsWith(root + "/") ? path__default['default'].posix.relative(root, file) : file; | ||
} | ||
var index = (paths, config = {}) => ({ | ||
name: "vite-plugin-live-reload", | ||
configureServer({ws, config: {root}}) { | ||
const reload = (path, action) => { | ||
configureServer({ws, config: {root, logger}}) { | ||
const reload = (path2) => { | ||
var _a; | ||
ws.send({type: "full-reload", path}); | ||
ws.send({type: "full-reload", path: path2}); | ||
if ((_a = config.log) != null ? _a : true) { | ||
console.log(chalk__default['default'].green(`[vite-live-reload] `) + `${path} ${action}.`); | ||
logger.info(chalk__default['default'].green(`page reload `) + chalk__default['default'].dim(getShortName(path2, root)), {clear: true, timestamp: true}); | ||
} | ||
}; | ||
chokidar__default['default'].watch(paths, {cwd: root, ignoreInitial: true, ...config}).on("add", (path) => reload(path, "added")).on("change", (path) => reload(path, "changed")); | ||
chokidar__default['default'].watch(paths, {cwd: root, ignoreInitial: true, ...config}).on("add", reload).on("change", reload); | ||
} | ||
@@ -27,0 +32,0 @@ }); |
{ | ||
"name": "vite-plugin-live-reload", | ||
"version": "2.0.0-beta.0", | ||
"version": "2.0.0", | ||
"description": "A *very* simple live reloading plugin for vite.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
import { Plugin, ViteDevServer } from 'vite' | ||
import chokidar, { WatchOptions } from 'chokidar' | ||
import chalk from 'chalk' | ||
import path from 'path' | ||
// https://github.com/vitejs/vite/blob/03b323d39cafe2baabef74e6051a9640add82590/packages/vite/src/node/server/hmr.ts | ||
function getShortName(file: string, root: string) { | ||
return file.startsWith(root + '/') ? path.posix.relative(root, file) : file | ||
} | ||
/** Plugin configuration */ | ||
@@ -22,14 +28,18 @@ interface Config extends WatchOptions { | ||
configureServer({ ws, config: { root } }: ViteDevServer) { | ||
const reload = (path: string, action: string) => { | ||
configureServer({ ws, config: { root, logger } }: ViteDevServer) { | ||
const reload = (path: string) => { | ||
ws.send({ type: 'full-reload', path }) | ||
if (config.log ?? true) { | ||
console.log(chalk.green(`[vite-live-reload] `) + `${path} ${action}.`) | ||
logger.info( | ||
chalk.green(`page reload `) + chalk.dim(getShortName(path, root)), | ||
{ clear: true, timestamp: true } | ||
) | ||
} | ||
} | ||
chokidar | ||
.watch(paths, { cwd: root, ignoreInitial: true, ...config }) | ||
.on('add', path => reload(path, 'added')) | ||
.on('change', path => reload(path, 'changed')) | ||
} | ||
.on('add', reload) | ||
.on('change', reload) | ||
} | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
5689
100
0