Gliding on robotic haulers, a line of Ferrari frames maneuvers through a gleaming new factory in Northern Italy. At each station, engineers in cherry red uniforms add a component — an engine block, a dashboard, a steering wheel — as they transform the bodies into hybrid vehicles. Up next: fully electric.

A lot is riding on Ferrari’s 200-million-euro “e-building,” which went into operation last month and is nearly twice the size of Rome’s Colosseum. The factory is intended to bring the 77-year-old sports-car maker, known for the sonorous vroom of its gas engines, into the age of electrification.

But the effort comes at a precarious time for the auto industry. The transition to electric vehicles, which was supposed to quickly usher in an era of climate-friendly transport, has instead been squeezed by costly investments and slowing global demand.

Other luxury carmakers have struggled to go electric. Mercedes-Benz and Lamborghini have reduced their ambitions. Tesla reported declining second-quarter sales on Tuesday, and Ford Motor said in April that it would shift production to more hybrids as E.V. losses piled up. A growing trade war between China and the West also threatens to stifle growth.

Despite the challenges, Ferrari sees an opportunity in the industry’s inevitable march toward electrification to reach a new consumer: the wealthy environmentalist. It intends to unveil its first fully electric model in the fourth quarter of next year. As part of its strategy, the carmaker has enlisted LoveFrom — the agency founded by Jony Ive, Apple’s former design chief, and the industrial designer Marc Newson — to hone the car’s appearance.