From 1ca96a4d8beefa6736cc43cdc5373d884ca00d2b Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Mon, 2 Jan 2023 17:19:18 -0500 Subject: [PATCH] fix css livereload Same issue as https://github.com/ef4/ember-auto-import/issues/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 https://github.com/embroider-build/embroider/issues/1315 --- packages/webpack/src/ember-webpack.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/webpack/src/ember-webpack.ts b/packages/webpack/src/ember-webpack.ts index 2ff21cfd2..1557a1056 100644 --- a/packages/webpack/src/ember-webpack.ts +++ b/packages/webpack/src/ember-webpack.ts @@ -418,7 +418,7 @@ const Webpack: PackagerConstructor = 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); } } @@ -433,6 +433,19 @@ const Webpack: PackagerConstructor = class Webpack implements Packager } } + private lastContents = new Map(); + + // 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);