Wikipedia says 4 companies produce 35 tons a year. It is produced something similar to the way that yeast is produced since you need microorganisms to create the B12. This is true for animals and us. The subsequent steps appear to convert the B12 created by the vats of bacteria to shelf stable, solid form.
65% of grain in the US alone is for livestock feed. For pesticides to grow that animal feed alone, to say nothing of fertilizers, fossil fuels for shipping refrigerating, etc, the US uses, 1 billion tons.
35 tons of B12 is a colossal amount. The daily recommendation is for dozens or hundreds of micrograms, I have no idea why we are creating so much. But even with this massive level of production of B12, it is 35/1000000000 of the chemical inputs necessary for the pesticides to grow the grains to feed the cows, etc.
So as a back of the envelope calculation, I'd have to be 7 orders of magnitude off for the inputs of animal agriculture to equal those of B12 production.
If we want to think outside of the box, then the environmentally friendly source of B12 is dirty water and dirty food, but that has problems of its own, like water borne diseases, and municipalities make sure there aren't any microbes that might have produced B12.