Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix css livereload #1317

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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