Skip to content

Commit

Permalink
fix css livereload
Browse files Browse the repository at this point in the history
Same issue as embroider-build/ember-auto-import#469 but in embroider rather than ember-auto-import.

The traditional livereload system will optimize reload if we don't touch files that don't need to be touched.

Fixes #1315
  • Loading branch information
ef4 committed Jan 3, 2023
1 parent 48c6adf commit 1ca96a4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/webpack/src/ember-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ const Webpack: PackagerConstructor<Options> = class Webpack implements Packager
// only the first variant should write it.
if (variantIndex === 0) {
for (let entrypoint of entrypoints) {
outputFileSync(join(this.outputPath, entrypoint.filename), entrypoint.render(stats), 'utf8');
this.writeIfChanged(join(this.outputPath, entrypoint.filename), entrypoint.render(stats));
written.add(entrypoint.filename);
}
}
Expand All @@ -433,6 +433,19 @@ const Webpack: PackagerConstructor<Options> = class Webpack implements Packager
}
}

private lastContents = new Map<string, string>();

// The point of this caching isn't really performance (we generate the
// contents either way, and the actual write is unlikely to be expensive).
// It's helping ember-cli's traditional livereload system to avoid triggering
// a full page reload when that wasn't really necessary.
private writeIfChanged(filename: string, content: string) {
if (this.lastContents.get(filename) !== content) {
outputFileSync(filename, content, 'utf8');
this.lastContents.set(filename, content);
}
}

private copyThrough(relativePath: string) {
let sourcePath = join(this.pathToVanillaApp, relativePath);
let newStats = statSync(sourcePath);
Expand Down

0 comments on commit 1ca96a4

Please sign in to comment.