Economy when warring

Hello. Newish player. My empire is great. 8k science, nexus on the way. Dominating neighbours, +1l alloys, 1k credits, 1 minerals etc. The Scourge attacks, I can fend for myself, but my economy crumbles. I've tried disabling science buildings, reorganizing my workers. But I really don't get it.

Why the sudden shift? What can I be over looking? Any experienced players with tips? How do you micro your empire, when crisis happens?