SHENZHEN, China—U.S. President-elect Donald Trump’s threat to compel Apple Inc. and others to manufacture more at home should strike fear into this Chinese megacity where many of the world’s high-tech gadgets are made.

Once a sleepy village, Shenzhen today is the sprawling epicenter of China’s consumer-electronics industry, the country’s top export. At two Foxconn Technology Group factories here, some 230,000 workers make gear for Apple and global rivals, including Chinese communications giant Huawei Technologies Co., which...