I have done that a couple of tines and the bikes are currently in a very enjoyable state, at least, for me, that is, no more upgrades are needed, until something breaks.
My main tactic is to keep an eye on prices of parts from both, reputable web pages and reputable local stores, and buy when the price is right.
Sometimes you can get slightly used parts for a fraction of its value. Some stores may have "clearance sales". I have had luck buying "OEM" parts (the web site claimed the parts where installed on bikes from factory that the customer wanted to upgrade right away, so the parts where unused and only with "installation marks")
Another way of obtaining good parts was to buy "new old stock", that is, new, unused parts that were a few years old model. When there is a new version of something, the old version decreases a bit in commercial value, and, if sitting on a shelf for too long, it often ends being sold at a discounted value.
Another key aspect of my success was that both bikes are MTB frames from around 1999, that had both v-brake and disc brake mounts, standard threading for bottom brackets and a tube to clamp the front derailleur. And during that period of time, until about 2012, more or less, not many standards changed. Sure, new things appeared but none was as disruptive as the complete change over from 26" to 27.5" and 29" or the almost disappearing of 2x and 3x drivetrains. The point here is that for quite a few years, new parts compatible with my bikes continued to be produced in relatively large quantities.
The advantage of my strategy is that I always had a rideable bike that I could enjoy, even if there where pending upgrades. Some times I used "cheap" or generic parts temporarily, understanding and accepting their limitations, until a good offer on some piece I needed appeared.
There are, however, some upgrades that are simply not feasible when done piece by piece, as other have stated. You could still acquire the parts separately, at different times, but that may pose the risk that later you can't find the compatible parts needed to complete assembly.
I would say, that the limitation is is whether the frame allow for upgrades and whether if is financially feasible to continue buying parts.
If you go on with your plan, do some research before, around the type of bike you plan on buying (Road, MTB, Touring, Etc) and around the type of riding your'e going to do. Search for what changes where there in the industry around the time the bike you plan on buying was sold initially.
Also, check if there is availability of parts for your specific location. (For example, I lived in a city where the local market was filled with the kind of parts that fit my 1999's bikes, On the other hands, to me, buying parts that are available only in Europe, would be nonsense due to shipping costs)