vite-plugin-reload-on-rebuild 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +6 -4
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +6 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -28,7 +28,8 @@ function reloadOnRebuild({
|
|
|
28
28
|
mode = "watch",
|
|
29
29
|
fileName = "reload-on-rebuild.js",
|
|
30
30
|
interval = 3e3,
|
|
31
|
-
headers = ["etag", "last-modified"]
|
|
31
|
+
headers = ["etag", "last-modified"],
|
|
32
|
+
filter = () => true
|
|
32
33
|
} = {}) {
|
|
33
34
|
let isWatchMode = false;
|
|
34
35
|
let basePath;
|
|
@@ -39,7 +40,7 @@ function reloadOnRebuild({
|
|
|
39
40
|
isWatchMode = !!config.build.watch;
|
|
40
41
|
basePath = config.base;
|
|
41
42
|
},
|
|
42
|
-
async generateBundle() {
|
|
43
|
+
async generateBundle(ctx) {
|
|
43
44
|
if (!enabled) return;
|
|
44
45
|
if (mode === "watch" && !isWatchMode) return;
|
|
45
46
|
this.emitFile({
|
|
@@ -55,7 +56,7 @@ function reloadOnRebuild({
|
|
|
55
56
|
for (const header of headers) {
|
|
56
57
|
const value = res.headers.get(header)
|
|
57
58
|
if (header in savedValues && savedValues[header] !== value) {
|
|
58
|
-
console.log('[vite-plugin-reload-on-rebuild]', '
|
|
59
|
+
console.log('[vite-plugin-reload-on-rebuild]', 'Header changed:', header, '(' + value + ').', 'Reloading...');
|
|
59
60
|
location.reload();
|
|
60
61
|
}
|
|
61
62
|
savedValues[header] = value
|
|
@@ -68,9 +69,10 @@ function reloadOnRebuild({
|
|
|
68
69
|
`.trim()
|
|
69
70
|
});
|
|
70
71
|
},
|
|
71
|
-
transformIndexHtml(html) {
|
|
72
|
+
transformIndexHtml(html, ctx) {
|
|
72
73
|
if (!enabled) return;
|
|
73
74
|
if (mode === "watch" && !isWatchMode) return;
|
|
75
|
+
if (!filter(ctx.path)) return;
|
|
74
76
|
return {
|
|
75
77
|
html,
|
|
76
78
|
tags: [
|
package/dist/index.d.cts
CHANGED
|
@@ -26,7 +26,13 @@ interface ReloadOnRebuildOptions {
|
|
|
26
26
|
* @default - ["etag", "last-modified"]
|
|
27
27
|
*/
|
|
28
28
|
headers?: string[];
|
|
29
|
+
/**
|
|
30
|
+
* Processes css file only if it's path matches provided filter
|
|
31
|
+
* @example (path) => Boolean(path.match(/src[\\/]index\.html/))
|
|
32
|
+
* @default () => true
|
|
33
|
+
*/
|
|
34
|
+
filter?: (path: string) => boolean;
|
|
29
35
|
}
|
|
30
|
-
declare function reloadOnRebuild({ enabled, mode, fileName, interval, headers, }?: ReloadOnRebuildOptions): Plugin;
|
|
36
|
+
declare function reloadOnRebuild({ enabled, mode, fileName, interval, headers, filter, }?: ReloadOnRebuildOptions): Plugin;
|
|
31
37
|
|
|
32
38
|
export { type ReloadOnRebuildOptions, reloadOnRebuild };
|
package/dist/index.d.ts
CHANGED
|
@@ -26,7 +26,13 @@ interface ReloadOnRebuildOptions {
|
|
|
26
26
|
* @default - ["etag", "last-modified"]
|
|
27
27
|
*/
|
|
28
28
|
headers?: string[];
|
|
29
|
+
/**
|
|
30
|
+
* Processes css file only if it's path matches provided filter
|
|
31
|
+
* @example (path) => Boolean(path.match(/src[\\/]index\.html/))
|
|
32
|
+
* @default () => true
|
|
33
|
+
*/
|
|
34
|
+
filter?: (path: string) => boolean;
|
|
29
35
|
}
|
|
30
|
-
declare function reloadOnRebuild({ enabled, mode, fileName, interval, headers, }?: ReloadOnRebuildOptions): Plugin;
|
|
36
|
+
declare function reloadOnRebuild({ enabled, mode, fileName, interval, headers, filter, }?: ReloadOnRebuildOptions): Plugin;
|
|
31
37
|
|
|
32
38
|
export { type ReloadOnRebuildOptions, reloadOnRebuild };
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,8 @@ function reloadOnRebuild({
|
|
|
4
4
|
mode = "watch",
|
|
5
5
|
fileName = "reload-on-rebuild.js",
|
|
6
6
|
interval = 3e3,
|
|
7
|
-
headers = ["etag", "last-modified"]
|
|
7
|
+
headers = ["etag", "last-modified"],
|
|
8
|
+
filter = () => true
|
|
8
9
|
} = {}) {
|
|
9
10
|
let isWatchMode = false;
|
|
10
11
|
let basePath;
|
|
@@ -15,7 +16,7 @@ function reloadOnRebuild({
|
|
|
15
16
|
isWatchMode = !!config.build.watch;
|
|
16
17
|
basePath = config.base;
|
|
17
18
|
},
|
|
18
|
-
async generateBundle() {
|
|
19
|
+
async generateBundle(ctx) {
|
|
19
20
|
if (!enabled) return;
|
|
20
21
|
if (mode === "watch" && !isWatchMode) return;
|
|
21
22
|
this.emitFile({
|
|
@@ -31,7 +32,7 @@ function reloadOnRebuild({
|
|
|
31
32
|
for (const header of headers) {
|
|
32
33
|
const value = res.headers.get(header)
|
|
33
34
|
if (header in savedValues && savedValues[header] !== value) {
|
|
34
|
-
console.log('[vite-plugin-reload-on-rebuild]', '
|
|
35
|
+
console.log('[vite-plugin-reload-on-rebuild]', 'Header changed:', header, '(' + value + ').', 'Reloading...');
|
|
35
36
|
location.reload();
|
|
36
37
|
}
|
|
37
38
|
savedValues[header] = value
|
|
@@ -44,9 +45,10 @@ function reloadOnRebuild({
|
|
|
44
45
|
`.trim()
|
|
45
46
|
});
|
|
46
47
|
},
|
|
47
|
-
transformIndexHtml(html) {
|
|
48
|
+
transformIndexHtml(html, ctx) {
|
|
48
49
|
if (!enabled) return;
|
|
49
50
|
if (mode === "watch" && !isWatchMode) return;
|
|
51
|
+
if (!filter(ctx.path)) return;
|
|
50
52
|
return {
|
|
51
53
|
html,
|
|
52
54
|
tags: [
|