Przeglądaj źródła

feat: automatically reload web pages whenever JS/CSS assets are rebuilt

version-14
Sagar Vora 3 lat temu
rodzic
commit
01d69b67c7
4 zmienionych plików z 27 dodań i 8 usunięć
  1. +8
    -2
      esbuild/esbuild.js
  2. +3
    -0
      frappe/build.py
  3. +13
    -4
      frappe/public/js/frappe/build_events/BuildSuccess.vue
  4. +3
    -2
      frappe/public/js/frappe/build_events/build_events.bundle.js

+ 8
- 2
esbuild/esbuild.js Wyświetl plik

@@ -44,6 +44,11 @@ let argv = yargs
type: "boolean", type: "boolean",
description: "Run in watch mode and rebuild on file changes" 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", { .option("production", {
type: "boolean", type: "boolean",
description: "Run build in production mode" description: "Run build in production mode"
@@ -475,7 +480,8 @@ async function notify_redis({ error, success }) {
} }
if (success) { if (success) {
payload = { payload = {
success: true
success: true,
autoreload: argv["auto-reload"]
}; };
} }


@@ -528,4 +534,4 @@ function log_rebuilt_assets(prev_assets, new_assets) {
log(" " + filename); log(" " + filename);
} }
log(); log();
}
}

+ 3
- 0
frappe/build.py Wyświetl plik

@@ -235,6 +235,9 @@ def watch(apps=None):
if apps: if apps:
command += " --apps {apps}".format(apps=apps) command += " --apps {apps}".format(apps=apps)


if frappe.conf.autoreload_on_build:
command += " --auto-reload"

check_node_executable() check_node_executable()
frappe_app_path = frappe.get_app_path("frappe", "..") frappe_app_path = frappe.get_app_path("frappe", "..")
frappe.commands.popen(command, cwd=frappe_app_path, env=get_node_env()) frappe.commands.popen(command, cwd=frappe_app_path, env=get_node_env())


+ 13
- 4
frappe/public/js/frappe/build_events/BuildSuccess.vue Wyświetl plik

@@ -3,8 +3,11 @@
v-if="is_shown" v-if="is_shown"
class="flex justify-between build-success-message align-center" 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 Refresh
</a> </a>
</div> </div>
@@ -14,11 +17,17 @@ export default {
name: "BuildSuccess", name: "BuildSuccess",
data() { data() {
return { return {
is_shown: false
is_shown: false,
autoreload: false,
}; };
}, },
methods: { methods: {
show() {
show(data) {
if (data.autoreload) {
this.autoreload = true;
this.reload();
}

this.is_shown = true; this.is_shown = true;
if (this.timeout) { if (this.timeout) {
clearTimeout(this.timeout); clearTimeout(this.timeout);


+ 3
- 2
frappe/public/js/frappe/build_events/build_events.bundle.js Wyświetl plik

@@ -13,10 +13,11 @@ frappe.realtime.on("build_event", data => {
} }
}); });


function show_build_success() {
function show_build_success(data) {
if (error) { if (error) {
error.hide(); error.hide();
} }

if (!success) { if (!success) {
let target = $('<div class="build-success-container">') let target = $('<div class="build-success-container">')
.appendTo($container) .appendTo($container)
@@ -27,7 +28,7 @@ function show_build_success() {
}); });
success = vm.$children[0]; success = vm.$children[0];
} }
success.show();
success.show(data);
} }


function show_build_error(data) { function show_build_error(data) {


Ładowanie…
Anuluj
Zapisz