They get a ton of tax incentives, subsidies, etc to build shoddy infrastructure that can only be used for big box stores (pretty much), so the end cost for Walmart to build their stores is quite low.
They promise to employ lots of locals, but many of those jobs are intentionally paid so low that they're not actually living wages and employees are intentionally driven to government help (food stamps, etc), and together with other various tax cuts, etc, there's a chance that even their labor costs are basically at break even.
Integrated local stores are better for pretty much everything except having a huge mass to throw around and bully, bribe (pardon me, lobby) and fool (aka persuade aka PR/marketing).
There is a reason why rural communities welcome Wal-Mart with open arms. Not such a big deal now that you can mail-order anything more-or-less instantly, but back in the 80s when I was growing up in BFE, Wal-Mart was a godsend.
It may have shifted where people buy things they can wait for, but for weekly shopping I don’t think it has.
Walmart spread so successfully precisely because so many people immediately started shopping there for all of the basics.