Skip to content

Commit

Permalink
Avoid unnecessary recompile at startup (#20176)
Browse files Browse the repository at this point in the history
When running the optimizer in dev mode, with new or updated entry files, the optimizer will run once and then a second time immediately after. This is because the webpack watcher uses really loose timestamp checks and since the entry files are created immediately before initializing the optimizer they are considered to be "changed" even when they aren't. To avoid this I've integrated the `webpack.WatchIgnorePlugin` to ignore the entry files from the watcher.


This could also be fixed by modifying the timestamps of the files after writing them to disk, but I didn't want extra FS access and it's not actually possible to change the entry files without completely restarting the optimizer.
  • Loading branch information
Spencer authored Jun 27, 2018
1 parent aa6c06e commit c8185cf
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/optimize/base_optimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,19 @@ export default class BaseOptimizer {
}
};

const watchingConfig = {
plugins: [
new webpack.WatchIgnorePlugin([
// When our bundle entry files are fresh they cause webpack
// to think they might have changed since the watcher was
// initialized, which triggers a second compilation on startup.
// Since we can't reliably update these files anyway, we can
// just ignore them in the watcher and prevent the extra compilation
/bundles[\/\\].+\.entry\.js/,
])
]
};

// in production we set the process.env.NODE_ENV and uglify our bundles
const productionConfig = {
plugins: [
Expand All @@ -361,7 +374,7 @@ export default class BaseOptimizer {
? {}
: transpileTsConfig,
this.uiBundles.isDevMode()
? supportEnzymeConfig
? webpackMerge(watchingConfig, supportEnzymeConfig)
: productionConfig
);
}
Expand Down

0 comments on commit c8185cf

Please sign in to comment.