Donald Trump blames Mexico and China for stealing millions of jobs from the United States.

He might want to bash the robots instead.

Despite the Republican presidential nominee's charge that "we don't make anything anymore," manufacturing is still flourishing in America. Problem is, factories don't need as many people as they used to because machines now do so much of the work.

America has lost more than 7 million factory jobs since manufacturing employment peaked in 1979. Yet American factory production, minus raw materials and some other costs, more than doubled over the same span to $1.91 trillion last year, according to the Commerce Department, which uses 2009 dollars to adjust for inflation. That's a notch below the record set on the eve of the Great Recession in 2007. And it makes U.S. manufacturers No. 2 in the world behind China.

Trump and other critics are right that trade has claimed some American factory jobs, especially after China joined the World Trade Organization in 2001 and gained easier access to the U.S. market. And industries that have relied heavily on labor — like textile and furniture manufacturing — have lost jobs and production to low-wage foreign competition. U.S. textile production, for instance, is down 46 percent since 2000. And over that time, the textile industry has shed 366,000, or 62 percent, of its jobs in the United States.

But research shows that the automation of U.S. factories is a much bigger factor than foreign trade in the loss of factory jobs. A study at Ball State University's Center for Business and Economic Research last year found that trade accounted for just 13 percent of America's lost factory jobs. The vast majority of the lost jobs — 88 percent — were taken by robots and other homegrown factors that reduce factories' need for human labor.

"We're making more with fewer people," says Howard Shatz, a senior economist at the Rand Corp. think tank.

General Motors, for instance, now employs barely a third of the 600,000 workers it had in the 1970s. Yet it churns out more cars and trucks than ever.

Or look at production of steel and other primary metals. Since 1997, the United States has lost 265,000 jobs in the production of primary metals — a 42 percent plunge — at a time when such production in the U.S. has surged 38 percent.

Allan Collard-Wexler of Duke University and Jan De Loecker of Princeton University found last year that America didn't lose most steel jobs to foreign competition or faltering sales. Steel jobs vanished because of the rise of a new technology: Super-efficient mini-mills that make steel largely from scrap metal.

The robot revolution is just beginning.

The Boston Consulting Group predicts that investment in industrial robots will grow 10 percent a year in the 25-biggest export nations through 2025, up from 2 or 3 percent growth in recent years.

The economics of robotics are hard to argue with. When products are replaced or updated, robots can be reprogrammed far faster and more easily than people can be retrained.

And the costs are dropping: Owning and operating a robotic spot welder cost an average $182,000 in 2005 and $133,000 in 2014 and will likely run $103,000 by 2025, Boston Consulting says. Robots will shrink labor costs 22 percent in the United States, 25 percent in Japan and 33 percent in South Korea, the firm estimates.

CEO Ronald De Feo is overseeing a turnaround at Kennametal, a Pittsburgh-based industrial materials company. The effort includes investing $200 million to $300 million to modernize Kennametal's factories while cutting 1,000 of 12,000 jobs. Automation is claiming some of those jobs and will claim more in the future, De Feo says.

"What we want to do is automate and let attrition" reduce the workforce, he says.

Visiting a Kennametal plant in Germany, De Feo found workers packing items by hand. He ordered $10 million in machinery to automate the process in Germany and North America.

That move, he says, will produce "better quality at lower cost" and "likely result in a combination of job cuts and reassignments."

But the rise of the machines offers an upside to some American workers: The increased use of robots — combined with higher labor costs in China and other developing countries — has reduced the incentive for companies to chase low-wage labor around the world.

Multinational companies are also rethinking how they spread production across the globe in the 1990s and 2000s, when they tended to manufacture components in different countries and then assemble a product at a plant in China or other low-wage country. The 2011 earthquake and tsunami in Japan, which disrupted shipments of auto parts, and the bankruptcy of the South Korean shipping line Hanjin Shipping, which stranded cargo in ports, exposed the risk of relying on far-flung supply lines.

"If your supply chain gets interrupted and your raw materials are coming from offshore, all of a sudden shelves are empty and you can't sell product," says Thomas Caudle, president of the North Carolina-based textile company Unifi.

So companies have been returning to the United States, capitalizing on the savings provided by robots, cheap energy and the chance to be closer to customers.

"They don't have all their eggs in that Asian basket anymore," Caudle says.

Over the past six years, Unifi has added about 200 jobs, bringing the total to over 1,100, at its automated factory in Yadkinville, North Carolina, where recycled plastic bottles are converted into Repreve yarn. Unmanned carts crisscross the factory floor, retrieving packages of yarn with mechanical arms — work once done by people.

In a survey by the consulting firm Deloitte, global manufacturing executives predicted that that the United States — now No. 2 — will overtake China as the most competitive country in manufacturing by 2020. (Competitiveness is measured by such factors as costs, productivity and the protection of intellectual property.)

The Reshoring Initiative, a nonprofit that lobbies manufacturers to return jobs to the United States, says America was losing an average of 220,000 net jobs a year to other countries a decade ago. Now, the number being moved abroad is roughly offset by the number that are coming back or being created by foreign investment.

Harold Sirkin, senior partner at Boston Consulting, says the global scramble by companies for cheap labor is ending.

Get the Monitor Stories you care about delivered to your inbox. By signing up, you agree to our Privacy Policy

"When I hear that (foreigners) are taking all our jobs — the answer is, they're not," he says.

The Christian Science Monitor reports that in reality, United States manufacturing output is at an all-time high, worth $2.2 trillion in 2015, up from $1.7 trillion in 2009. And while total employment has fallen by nearly a third since 1970, the jobs that remain are increasingly skilled.