You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
Repository navigation
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
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).
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.
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.
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.
I have been running `webpack -w` as a separate independent process for a
while. Implicitly running it for every dotnet rebuild is not good design.
Thank you for your comments, nonetheless.
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.
Activity
SteveSandersonMS commentedon Jan 6, 2017
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 commentedon Feb 20, 2017
One possible option, which is far from perfect, but worked for me:
WebpackMiddleware, which does not usingConditionalProxyMiddlewareoutput: { path: '/yourwwwroot' })wwwrooton 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 dodotnet runit 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
wwwrootcleanup youself, but you can make a separate webpack configs - one for dev-middleware mode and one for usual webpack build.SteveSandersonMS commentedon May 22, 2017
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 commentedon May 22, 2017
eugene159 commentedon Mar 8, 2018
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.