I've done it both ways--cooking them first and adding them raw. I prefer to sweat the onions and other vegetables first because it ensures they are cooked and tender. I'm a huge onion fan, but undercooked onions in a meatloaf in my opinion is a bit offputting.