Bernie would have won, if the matchup were between Trump and him.
Socialist nationalism is more popular then demographic/militaristic nationalism.
Hillary won because:
1) the DNC rigged the nomination by giving her all superdelegates
2) Bernie stood down on the Hillary email scandal (still under Congressional and FBI investigation).
Bernie should have opened his mouth and slammed Hillary for her criminality. Instead, he gave her a pass. So the DNC threw Sanders under the bus.
No good deed goes unpunished, apparently.