Skip to content

Commit

Permalink
Merge pull request #1317 from embroider-build/fix-css-livereload
Browse files Browse the repository at this point in the history
fix css livereload
  • Loading branch information
ef4 committed Jan 4, 2023
2 parents 6983c1e + 1ca96a4 commit aa97453
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 @@ -429,7 +429,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 @@ -444,6 +444,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 aa97453

Please sign in to comment.