From 112067b6bfa127562c04f8b07e98bf0923e0571a Mon Sep 17 00:00:00 2001 From: Craig Beck Date: Tue, 25 Apr 2023 16:09:03 -0700 Subject: [PATCH] Fix static build failing due to view caching (#16) * Ensure listeners not added and viewcache is initilized when building static assets * Do not register app if not static build --- lib/DerbyViewPlugin.js | 8 +++++++- lib/plugin.js | 10 ++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/DerbyViewPlugin.js b/lib/DerbyViewPlugin.js index 86ecde1..1c419b9 100644 --- a/lib/DerbyViewPlugin.js +++ b/lib/DerbyViewPlugin.js @@ -24,6 +24,10 @@ DerbyViewsPlugin.prototype.apply = function(compiler) { virtualViewFilesInitialized = true; Object.entries(appNameToPath).forEach(([appName, requirePath]) => { const appPath = require.resolve(requirePath, { paths: [rootPath] }); + if (!process.env.DERBY_HMR) { + const app = require(appPath); + viewCache.registerApp(app); + } function updateVirtualViewsFile() { const viewSource = viewCache.getViewsSource(appPath); if (viewSource) { @@ -33,7 +37,9 @@ DerbyViewsPlugin.prototype.apply = function(compiler) { } } updateVirtualViewsFile(); - viewCache.addViewUpdateListener(appPath, updateVirtualViewsFile); + if (process.env.DERBY_HMR) { + viewCache.addViewUpdateListener(appPath, updateVirtualViewsFile); + } }); } diff --git a/lib/plugin.js b/lib/plugin.js index 34dfa0d..0c06c77 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -28,10 +28,12 @@ function pluginForAppInstance(app) { } } - viewCache.registerApp(app); - app._updateScriptViews = function() { - viewCache.refreshApp(this); - }; + if (process.env.DERBY_HMR) { + viewCache.registerApp(app); + app._updateScriptViews = function() { + viewCache.refreshApp(this); + }; + } function middlewareAssets(page) { const { devMiddleware } = page.res.locals.webpack;