Complex sentence: Sugar remained an important export commodity, but it fell in importance in Brazil, which shifted to coffee cultivation, but expanded in the last Spanish colonies of Cuba and Puerto Rico with African slave labor, which was still legal in the Spanish empire.
Split into simpler sentences: Sugar remained an important export commodity, but it fell in importance in Brazil, which shifted to coffee cultivation. Sugar expanded in the last Spanish colonies of Cuba and Puerto Rico with African slave labor, which was still legal in the Spanish empire.