Around the world the gears of globalization are shifting into reverse.

Companies spent decades farming out every step of production according to where inputs—labor, infrastructure, know-how—were optimally located. Now, as trade barriers rise, they are grappling with how to localize production again.

Harley-Davidson Inc.’s plans to move some...