feat: automatically reload web pages whenever JS/CSS assets are rebuilt
This commit is contained in:
parent
3bde63eca2
commit
01d69b67c7
4 changed files with 27 additions and 8 deletions
|
|
@ -44,6 +44,11 @@ let argv = yargs
|
|||
type: "boolean",
|
||||
description: "Run in watch mode and rebuild on file changes"
|
||||
})
|
||||
.option("auto-reload", {
|
||||
type: "boolean",
|
||||
description: `Automatically reload webpages when assets are rebuilt.
|
||||
Can only be used with the --watch flag.`
|
||||
})
|
||||
.option("production", {
|
||||
type: "boolean",
|
||||
description: "Run build in production mode"
|
||||
|
|
@ -475,7 +480,8 @@ async function notify_redis({ error, success }) {
|
|||
}
|
||||
if (success) {
|
||||
payload = {
|
||||
success: true
|
||||
success: true,
|
||||
autoreload: argv["auto-reload"]
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -528,4 +534,4 @@ function log_rebuilt_assets(prev_assets, new_assets) {
|
|||
log(" " + filename);
|
||||
}
|
||||
log();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -235,6 +235,9 @@ def watch(apps=None):
|
|||
if apps:
|
||||
command += " --apps {apps}".format(apps=apps)
|
||||
|
||||
if frappe.conf.autoreload_on_build:
|
||||
command += " --auto-reload"
|
||||
|
||||
check_node_executable()
|
||||
frappe_app_path = frappe.get_app_path("frappe", "..")
|
||||
frappe.commands.popen(command, cwd=frappe_app_path, env=get_node_env())
|
||||
|
|
|
|||
|
|
@ -3,8 +3,11 @@
|
|||
v-if="is_shown"
|
||||
class="flex justify-between build-success-message align-center"
|
||||
>
|
||||
<div class="mr-4">Compiled successfully</div>
|
||||
<a class="text-white underline" href="/" @click.prevent="reload">
|
||||
Compiled successfully
|
||||
<a
|
||||
v-if="!autoreload"
|
||||
class="ml-4 text-white underline" href="/" @click.prevent="reload"
|
||||
>
|
||||
Refresh
|
||||
</a>
|
||||
</div>
|
||||
|
|
@ -14,11 +17,17 @@ export default {
|
|||
name: "BuildSuccess",
|
||||
data() {
|
||||
return {
|
||||
is_shown: false
|
||||
is_shown: false,
|
||||
autoreload: false,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
show() {
|
||||
show(data) {
|
||||
if (data.autoreload) {
|
||||
this.autoreload = true;
|
||||
this.reload();
|
||||
}
|
||||
|
||||
this.is_shown = true;
|
||||
if (this.timeout) {
|
||||
clearTimeout(this.timeout);
|
||||
|
|
|
|||
|
|
@ -13,10 +13,11 @@ frappe.realtime.on("build_event", data => {
|
|||
}
|
||||
});
|
||||
|
||||
function show_build_success() {
|
||||
function show_build_success(data) {
|
||||
if (error) {
|
||||
error.hide();
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
let target = $('<div class="build-success-container">')
|
||||
.appendTo($container)
|
||||
|
|
@ -27,7 +28,7 @@ function show_build_success() {
|
|||
});
|
||||
success = vm.$children[0];
|
||||
}
|
||||
success.show();
|
||||
success.show(data);
|
||||
}
|
||||
|
||||
function show_build_error(data) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue