Move all web assets to shared cached space

Put all web assets including plugin assets under a shared static/ route
in the web interface that's declared as immutable and cacheable for 1
year.  This allows all JavaScript bundles to be loaded from disk instead
of having to check with the web server each time and significantly
speeds up the web interface load time.  It also fixes the public path
issue when using the --dev-plugin option behind a proxy.

To prevent collisions and stale data all assets now include a hash in
the filename.  This means the entrypoint is now dynamic and specified in
a manifest.json file created from the web build.  For plugins this means
the filename attribute needs to be removed from webpack.config.js.
This commit is contained in:
Hornwitser committed 2022-06-08 21:01:36 +02:00
1 parent 2401fe25fa
commit e32637503d
14 files changed
+90 -33

No files matched your search

+8 -1
View File
@@ -39,8 +39,12 @@ async function loadPlugins() {
let plugins = new Map();
await __webpack_init_sharing__("default");
for (let meta of pluginList) {
if (meta.web.error) {
logger.error(`Failed to load plugin ${meta.name}: ${meta.web.error}`);
continue;
}
try {
await loadScript(`${webRoot}plugins/${meta.name}/remoteEntry.js`);
await loadScript(`${webRoot}${meta.web.main}`);
let container = window[`plugin_${meta.name}`];
if (!container) {
throw new Error(`Plugin did not expose its container via plugin_${meta.name}`);
@@ -63,6 +67,9 @@ async function loadPlugins() {
plugins.set(pluginInfo.name, plugin);
} catch (err) {
if (err.message) {
meta.web.error = err.message;
}
logger.error(`Failed to load plugin ${meta.name}`);
if (err.stack) {
logger.error(err.stack);
@@ -51,7 +51,7 @@ export default function PluginViewPage() {
style={{
marginTop: "1em",
}}
message="Error loading web module"
message={pluginMeta.web.error || "Error loading web module"}
description={
"The web interface was unable to load the webpack module for this plugin. This is "+
"usually due to an incorrect or missing webpack build for the plugin. Due to the "+