"...and also roll a saving throw against that fireball for your equipment. Oh, right! You are carrying a small keg of gunpowder, aren't you....?"
The first thing that happens in my campaign world whenever some player that thinks they are clever does the clever and creative thing that countless such players have tried in countless games before him is that NPC's laugh at him.
You see, unlike the player or the player's character, the NPC's have ranks in alchemy and knowledge (history) and so forth, and they know just how incredibly stupid this idea is and how disastrously it has failed in the past. Far from being a novel idea, "firearms" have been invented 3 or 4 times in the past by would be world conquerors (most of them goblins who delight in such things), only to have their efforts end in ridiculous calamity. Indeed, in learned circles, the names of such would be BBEG's are bywords for folly - figures of comedy rather than figures that inspire terror.
One of the central tenants of my campaign world is that the PC's are not more clever than NPC's. Anything that a clever player or PC is likely to think of is likely to be something that some NPC in the 10,000 year written history of the world has also tried. Quite naturally, the learned alchemists of the world have recognized the potential value of explosives and have spent 1000's of years of collective effort researching practical explosives. By the time a player proposes this sort of thing, whole libraries of books researching the problem have been written. And what all that effort has so far discovered is that practical explosives are hard. The most practical explosives known have a brisance equivalent to blackpowder, but a stability and shelf-life slightly on the touchy side of raw nitroglycerine. So you can in fact make a bomb, or a grenade, or a firearm. That's easy, and any master alchemist in a large town in theory could do it (although most of them will refuse to do so because they have an unreasonable attachment to their fingers). What you can't however do is safely store or transport such an item, especially in large enough quantities to supply an army. And if you try, the almost inevitable result is that your stockpile of munitions is of greater threat to you than it is to your enemy. And one wizard on the opposing side with ranged fire spell or a summoned fire elemental, can trigger a chain reaction that will decimate your entire army.
So sure, you can spend a great deal of resources building up an army of musketeers and grenadiers. But don't expect to be the first person who has thought of this idea or for it to turn the game into easy mode. By all means, take some ranks in alchemy and build yourself a bomb or some grenades for your personal use. I will do nothing to stop you. Just don't expect this to be cheating.