-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin-append-script.js
29 lines (26 loc) · 1.12 KB
/
plugin-append-script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* This code is added by the rollup-plugin-reloadsite plugin
* Naturally, this plugin is disabled as soon as you stop watching your source files via the -w flag
* process.env.ROLLUP_WATCH is used to automatically mute the plugin and this code, as well as the actual ReloadSite server will disappear
* However, it is better to be explicit in your code and only load the rollup-plugin-reloadsite plugin in development mode
*
* Note: If you have run multiple sources, then you might find this code in multiple files.
* However, it's effect is limited to only one time as the if condition below should stop all other instances from running
*/
// see if script tag exists
(function () {
let scriptExists = document.querySelector('script#ReloadSite');
if (!scriptExists) {
// get document body
let body = document.querySelector('body,html');
if (body) {
// create tag
let tag = document.createElement('script');
tag.src = 'http://127.0.0.1:{PORT}/reloadsite.js';
tag.id = 'ReloadSite';
body.append(tag);
} else {
console.warn('HTML document has no body or html tag!');
}
}
})();