Ok... we have little to no information on how long it takes to build a starship.
There's a difference between designing a starship on a drawing board (which could easily take months or years) to actual construction/completion (which could easily take a few weeks).
Novels are not canon... and lets not forget that use of automation would have to be paramount in space (which is thousands of times faster/better than humans/humanoids).
Let us also recall that in ST Voyager, it took the crew about a week to build the Delta Flyer... and again we don't know what it took to built it (the way it was portrayed, it seemed as if the crew mainly did it - which to me is ridiculous). Voyager has an assortment of technologies at its disposal such as tractor beams and replicators, and their computer is highly advanced (meaning, it can do the construction all by itself).
If anything similar to 3d printers exists in Trek in the 23rd century (which the probably do and are far more advanced/faster than what we have and would likely predate the replicators), then it stands to reason the Federation could easily deploy these automated construction 3d printers to build a starship in a very short span of time (within a month possibly).
A space station (depending on size) would take longer... but this depends on how many theoretical automated 3d printers are used in construction vs a starship.
In the 24th century, I don't see why replicating whole starships... or most of them in pieces, would be impossible. Drydocks and construction facilities have massive energy reserves at their disposal, and replicators in that time could easily be drawing Zettajoules of power directly from the star itself in addition to using Matter/Antimatter.
For the 23rd century, a similar process would likely take place using 3d printers that can produce whole structures... along with internal circuitry (btw, 3d printers CAN 'replicate' houses with electrical wiring btw) in a very short span of time.
And since the Federation was usually portrayed as an organisation that creates modular type technology... it stands to reason that as others have said, these structures would simply be attached to each other upon completion.
So, how fast something would be built depends on how much automation you really throw at the task.
The 24th century can easily replicate everything into existence by converting energy into matter.
The 23rd would need access to raw materials... and those are usually pretty much common throughout virtually every solar system.
And since technical efficiency allows us to do more with less, the Federation would likely be able to take a very miniscule amount of materials and use them in a creation of a starbase (which could conceivably take about several weeks to months until completion or less - automation is exceedingly efficient and fast... plus, we cannot simply view things from a slower point of view as it's happening in real life... the Federation is massively far more advanced in comparison to us, and we are capable of some amazing feats... the Federation would in comparison be thousands of orders of magnitude faster/better than us (and that's at a bare minimum).