Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Have option in UseWebpackDevMiddleware to load existing js files on startup #555

Closed
rhyek opened this issue Jan 4, 2017 · 5 comments
Closed

Comments

@rhyek
Copy link

rhyek commented Jan 4, 2017

This is in relation to #545. Currently using VC Code to work on a ASP.Net Core/VueJS project. I'm using dotnet-watch to automatically restart the server on backend code changes. Doing so also restarts webpack fully. This adds 3-5s to an already lengthy ~10s just from restarting the server.

This is on a new project with barely any custom code. I feel it is important to shave off any build times wherever possible.

I would appreciate an option to just serve existing compiled js files when restarting the server. JS files are compiled every time on save, so I believe it's generally unnecessary to do so on server restart as well (I may be wrong about this).

@SteveSandersonMS
Copy link
Member

In general I'm open to this possiblity, but one potential drawback is that it could be very confusing to developers.

For example, if you edit some TypeScript code, and then start up your app, you'd expect to see the latest version of your code running in the browser, but with this option you might still see the previous version running, depending on whether the Webpack compilation completed before or after the page load completed. Inconsistencies like that may seem random to unfamiliar developers, leading to time wasted tracking down nonexistent bugs.

Ideally we'd serve the previously-compiled files only if we know the source files haven't changed in the meantime, but I'm not sure there'd be a simple and reliable way to know that.

@Aleksanderis
Copy link

One possible option, which is far from perfect, but worked for me:

  • create WebpackMiddleware, which does not using ConditionalProxyMiddleware
  • configure webpack so, that it outputs built files to wwwroot (output: { path: '/yourwwwroot' })
  • don't cleanup wwwroot on each webpack build (don't use CleanWebpackPlugin or similar thing)

It will work so, that all webpack output will be put into wwwroot, but updated only after build is finished. When you do dotnet run it will initiate webpack build, but while it's still building - it will serve previously compiled files, which should make initial load faster.
Yes, you will need to care about wwwroot cleanup youself, but you can make a separate webpack configs - one for dev-middleware mode and one for usual webpack build.

@SteveSandersonMS
Copy link
Member

A few months of thought later, I no longer think this is something we should do, at least not as a built-in feature. The cost of continually confusing developers by sometimes running old versions of the code, ignoring your latest changes (but not always! it's a race condition!), is likely to outweigh the benefit of shaving a few seconds off the build time. If someone one day comes up with a proposed implementation that gives the benefits without the costs, we can certainly reconsider.

@Aleksanderis's technique above is a good approach for more confident developers who want to take manual responsibility for this.

@rhyek
Copy link
Author

rhyek commented May 22, 2017 via email

@eugene159
Copy link

Is there any way not to re-build typescript when I run my project with CTRL-F5, but still have HMR ? I want to rebuild it myself by running webpack in watch mode.
I have huge Angular app and every time I change something on the backend it rebuilds the whole Angular side that takes about a minute. This drives me crazy.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants