When a barbarian is enraged, it says it has resistance to damage such as piercing, slashing etc. (which to my knowledge just halves the number and rounds down). So does that mean it has resistance to any non-magical melee attack, or does that just mean the extra bit of damage at the end (e.g +2 bludgeoning) is halved? I'd really appreciate any info on this.
It resists the entire damage that has that damage type.
It seems you are misunderstanding how the damage works. I randomly picked a monster from the monster manual to exemplify the scenario. The Deva has this attack:
Mace. Melee Weapon Attack: +8 to hit, reach 5 ft. , one target. Hit: 7 (1d6 + 4) bludgeoning damage plus 18 (4d8) radiant damage.
This reads as: (1d6 + 4) damage is bludgeoning damage. This damage is halved by the barbarian resistance. Say you got a 3 in the d6, the total bludgeoning damage would be 7. This is then reduced to 3 (as you said, rounded down). The (4d8) damage is not resisted by the barbarian, though, so let's say the monster rolled 3, 5, 1, 4 = 13 radiant damage. The barbarian is taking a total of 16 damage.
In particular, it seems you might be thinking that only the +4 would be bludgeoning damage, but that's a misunderstanding - the 1d6 is also part of the bludgeoning damage, thus is also reduced.
Every point of damage (dice or constant) has its own type1 2 . The barbarian resists every damage done by the types listed. For completionism, Crawford makes the same statement in his tweet:
All damage has a type. #DnD
A final minor misconception is that you state
So does that mean it has resistance to any non-magical melee attack
It resists to magical damage from these types too, though. There are spells that do Bludgeoning damage, as well as magical weapons that do these types of damage.
1 For the sake of completionism and clarity, the possible types of damage are listed in the Damage and Healing section, under the Combat chapter, in a sub-section specific for Damage Types. They are: Acid, Bludgeoning, Cold, Fire, Force, Lightning, Necrotic, Piercing, Poison, Psychic, Radiant, Slashing and Thunder.
2 Some features, such as Hunter's Mark from Ranger or Sneak Attack from rogue do not specify the type of damage. This is clarified by Crawford in this sequence of tweets.
Hunter's mark uses the same damage type as the attack that triggers it. If the attack has more than one damage type, choose one.
This can be explained by the fact that the Hunter's Mark or the Sneak Attack simply increase the damage being done by the current attack, not changing its type.
The resistance is to all of the damage.
When the raging barbarian takes bludgeoning, piercing, or slashing damage, the damage is halved in its entirety.
Your confusion seems to come from the way damage is often listed in a monster's stat block. For example, if an attack deals 2d6+3 bludgeoning damage, that's not "2d6 damage plus 3 bludgeoning damage"; it's "an amount of bludgeoning damage equal to 2d6 plus 3." The entire number generated by rolling the dice and adding the modifier is the damage amount, and that's the damage that is resisted by the raging barbarian.
Resistance applies to the total damage after all modifiers have been added or subtracted.
If you mean "Do I apply resistance to only the dice result, and not any magical bonus to damage that may apply", then no. For example, if you were hit by a creature using a magical +1 handaxe, with a 12 strength granting them a +1 bonus to damage, then the damage would be "1d6+1+1", and the resistance applies to the total after modifiers.
Specifically, barbarian's resistance while raging is also applied against magical weapons. Hope that helps!
Here's a quote from the basic rules about resistance:
Resistance and then vulnerability are applied after all other modifiers to damage. For example, a creature has resistance to bludgeoning damage and is hit by an attack that deals 25 bludgeoning damage. The creature is also within a magical aura that reduces all damage by 5. The 25 damage is first reduced by 5 and then halved, so the creature takes 10 damage.