The fact that an assembly line of workers specialized to a single stage of a production process works better than a bunch of generalists working in parallel seems like a really basic insight. Groups of children regularly invent it independently, and we know for certain that things like the bucket chain have existed for thousands of years. Despite this, it seems like the assembly line was only adopted as the default method of producing things within the past few hundred years. Wikipedia lists a few historical examples of premodern assembly lines here and here, but it seems like these were the exception rather than the rule, and existed mostly in a military context. What are the factors behind this? What advantages did craft production have in the premodern world that allowed it to compensate for its clear disadvantage in efficiency compared to an assembly line?
Not a historian by profession but have studied a lot related to machining, machine tool development etc that all came about at the end of the 1800s/early 1900s. My citations are limited as I'm typing this up largely from memory at 4am on my phone but if you'd like to know more on any subject, I can look through my library for suggestions.
If you look at how most things were made, a skilled crafts person would custom make and fit pieces of an assembly together. Parts weren't interchangeable for much of what was produced. Much of the metal parts made were heavily filed to fit into other parts/to achieve whatever function. See die filing machines and hand filing.
Assembly lines benefit from interchangeable parts. If you don't have interchangeable parts, it'd be like proposing that someone make a stitch in some fabric then pass it off to the next person to do the next one. You needlessly complicate the process for no real gain.
"Modern" machine tools started to exist in the 1700 to 1800 century with rapid growth in the 1800-early 1900s. Lathes in some capacity have existed much further back but were crude implements compared to metal working machines.
A number of technologies had to develop: availability of power, precise and accurate screws, metrology and material science to make machine tools work.
Water turbines were developed extensively in the 19th century such as the Knight wheel and the Patton wheel allowing for better power generation compared to a simple water wheel dating to antiquity. These impulse driven wheels were often connected to line shafts with belts that could transmit power all over a factory on the ceiling with a leather belt connecting to whatever machine was needed. Functional versions of this still exist today such as at Knight's Foundry.
Precise and accurate screws were the foundation of machine tool positioning and still are today (but we have more complex options as well using closed loop feedback sensors.) Screws has existed for much of human history but we didn't start seeing accurate lead screws until the late 1700s and into the 1800s. Maudslay is known as a founding father of machine tools. He developed a metal cutting lathe to turn (cut) threaded rods. To be accurate, you need the form of the thread such as it's pitch to be consistent throughout since that screw is going to be used to position parts of other machines. If I turn the thread of a 40 tpi (threads per inch), one revolution, I'll get 1/40 = 0.025" movement on a nut riding the screw. This is the how micrometers and specifically inch micrometers work. Same with machine tools. Your average Bridgeport milling machine usually has 0.250" per revolution of the screw in the x and y axis. Simon Winchester has a great layperson targeted book on the history of precision. It seems to go by a few different names based on the country that version of the book was marketed at. It focuses heavily on time keeping as accurate time keeping and precision work was needed to enable better navigation at sea, solving the longitude problem.
Now you have power for the machines and machines that can reliably make parts similar to eachother but you also need a way to measure parts. This didn't pre-date assembly lines but certainly helped them. Carl Edward Johansson developed a technique to make very accurate gauges (millionth of an inch) and a system of using stacks of gauges in different configurations to reproduce any reference length needed for the average machinist. Commonly known as gauge or jo blocks, his idea didn't initially take off. Some car companies in America were already working with assembly lines or trying. Ford saw CEJ's product and hired him to implement the gauge block system in his factories. Similarly, Palmer in France, developed and marketed the first screw micrometer at the end of the 1800s. Then Brown and Sharpe improved on the design followed by many others and marketed it heavily in the US.
Now you have the ability to accurately make and measure parts to verify they met a standard size within some tolerance. Before, you couldn't easily make a batch of parts to install in an assembly line that could reasonably fit and be interchangeable. Rapid industrial expansion also fueled a need for higher production rates.
Additionally, material science was developing with the invention of better materials for cutting tools to support these processes. Steel itself was only available limitedly prior to the end of the 1700s as new methods of steel production produced higher quality product at a faster rate. Steel is much stronger than cast iron which was more commonly used before steel production became economically feasible at scale.