Skip to content

Commit

Permalink
Fix static build failing due to view caching (#16)
Browse files Browse the repository at this point in the history
* Ensure listeners not added and viewcache is initilized when building static assets

* Do not register app if not static build
  • Loading branch information
craigbeck authored Apr 25, 2023
1 parent 9aaea6e commit 112067b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 7 additions & 1 deletion lib/DerbyViewPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -33,7 +37,9 @@ DerbyViewsPlugin.prototype.apply = function(compiler) {
}
}
updateVirtualViewsFile();
viewCache.addViewUpdateListener(appPath, updateVirtualViewsFile);
if (process.env.DERBY_HMR) {
viewCache.addViewUpdateListener(appPath, updateVirtualViewsFile);
}
});
}

Expand Down
10 changes: 6 additions & 4 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 112067b

Please sign in to comment.