Against an undefended or lightly-defended target, sure, the blaster is going to be the right choice of weapon, but when armor comes into the picture, a lightsaber starts looking like a meaningful choice if you can engineer the encounter to allow you to employ it.
Problem is, how many times were lightsabers actually used against heavily armored targets as opposed to regular ground troops? Not much. Maybe a few tanks and doors, but for the large part Jedi in the movies act as elite ground troops that fight against infantry, or stealth insertion troops. Giving them a sniper rifle would probably give them more kills if they can be given the range, and if they need to be on the front lines/behind the lines a shield made from hull material plus a strong pistol blaster would be better. While lightsaber deflection is nice in that it can reflect blaster bolts back, it leaves them vulnerable to mass fire, as seen in episode 3 with order 66. A shield is a much better defense, and leaves the Jedi much more attention space to focus on shooting.
Side note: if Star Wars actually followed logic, killing a Jedi with blasters is actually really easy if you can prepare. The super battle droids had a weapon called a triblaster, which fired 3 simultaneous shots in a triangle. By all rights this should be impossible for a Jedi armed with a near 1 dimensional defense to block fully.
Part of the problem is that it takes extremely exacting circumstances for lightsabers to be useful at all. Jedi need to have both super speed, and a very precise form of precog that only gives them enough time to move the blade but not move out of the way. Enhanced stamina is the only way they can actually use a lightsaber as their sole weapon, because otherwise they would tire out too fast. Against other force users, some form of plot contrivance is needed so that the fight isn't solely telekinesis.
All of this, years of training, custom made weapons, can occasionally outcompeted some dude that picks up a gun and can aim, something that needs vastly less training.
Star Wars also has defenses versus ranged attacks being fairly commonplace -- ships and droids have deflectors; Jedi have blaster parry.
Aside from droidekas, I don't remember any type of deflectors for infantry, and I don't think lightsabers could get through the droideka shields either. And as mentioned above, lightsabers aren't even a great defense if the enemy actually is aware of how lightsabers work, and their limitations.
Defenses versus melee attacks are mostly limited to armor, and the melee weapon in question is specifically designed to overcome armor as mentioned above.
If the need is to get through a reinforced door, then yes a lightsaber is a decent method. For taking out heavy machinery like tanks or AA guns, grenades and various explosives are much better, partially because they can be deployed at range. But then a lightsaber is merely a tool, not a good weapon.
So really, the best weapon in Star Wars OUGHT to be a rocket-propelled lightsaber. Ridiculously expensive, but you can be sure that whatever you hit
Lightsabers encounter resistance, as seen in one of the prequels where they go through a door, so angled armor almost completely negates that.
To summarize and put back more on topic, I'm not saying that melee weapons are always inferior to ranged weapons and have no place in any setting above a certain tech level. They have their uses, even in WTR. If you need something that doesn't run out of charge or bullets, a sword is good. OL used x-ionised swords against Sabbac because they're good at piercing defenses, the sword of the fallen can kill anything it can hit, Grayven has a sword because it can apply exotic effects, and Nth metal weapons are great against energy barriers. This all makes sense. But for the vast majority of cases, a simple gun is going to be a better choice. Melee weapons should be fringe case tools, stuff brought out to counter something specific, not a general use weapon that is used as someone's sole source of damage dealing. Grayven saw far more trouble from massed gunfire than from some guys with maces that he could simply fly away from.