Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 80c0eb6

Browse files
committed
fix(rollup): invalidate cache on template change
1 parent 11a949d commit 80c0eb6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/rollup.ts

+3
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ function checkDeprecations(context: BuildContext, rollupConfig: RollupConfig) {
143143
}
144144
}
145145

146+
export function invalidateCache() {
147+
cachedBundle = null;
148+
}
146149

147150
let cachedBundle: RollupBundle = null;
148151

src/template.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { BuildContext, BuildState, File } from './util/interfaces';
2+
import { changeExtension } from './util/helpers';
23
import { Logger } from './logger/logger';
34
import { getJsOutputDest } from './bundle';
5+
import { invalidateCache } from './rollup';
46
import { dirname, extname, join, parse, resolve } from 'path';
57
import { readFileSync, writeFile } from 'fs';
68

@@ -23,6 +25,9 @@ export function templateUpdate(event: string, htmlFilePath: string, context: Bui
2325
const successfullyUpdated = updateCorrespondingJsFile(context, newTemplateContent, htmlFilePath);
2426
bundleSourceText = replaceExistingJsTemplate(bundleSourceText, newTemplateContent, htmlFilePath);
2527

28+
// invaldiate any rollup bundles, if they're not using rollup no harm done
29+
invalidateCache();
30+
2631
if (successfullyUpdated && bundleSourceText) {
2732
// awesome, all good and template updated in the bundle file
2833
const logger = new Logger(`template update`);
@@ -60,6 +65,11 @@ function updateCorrespondingJsFile(context: BuildContext, newTemplateContent: st
6065
const newContent = replaceExistingJsTemplate(javascriptFile.content, newTemplateContent, existingHtmlTemplatePath);
6166
if (newContent !== javascriptFile.content) {
6267
javascriptFile.content = newContent;
68+
// set the file again to generate a new timestamp
69+
// do the same for the typescript file just to invalidate any caches, etc.
70+
context.fileCache.set(javascriptFile.path, javascriptFile);
71+
const typescriptFilePath = changeExtension(javascriptFile.path, '.ts');
72+
context.fileCache.set(typescriptFilePath, context.fileCache.get(typescriptFilePath));
6373
return true;
6474
}
6575
}

0 commit comments

Comments
 (0)