During infection a body has to produce absolute masses of immune cells, raise your temperature via increased metabolism, repair tissue damage, migrate components of the immune system including proteins and cells, produce masses of antibodies and probably lot's more.
A lot of protein components need to be made which require protein synthesis and energy. Metabolism of fats and carbs goes up too. Also, importantly, vitamins are a key part of the immune system serving to migrate the immune system such as vitamin D aids migration of cells to the skin. Vitamin C is required for collagen synthesis in repair. Minerals are required for the metalloenzymes. However your dependency on each component depends on the type of infection, your immune response, your natural state including your reserves of everything.
How important is it? Very. I've listed what the things are needed for which gives an indication of how important they are. If starved, the body will do the best it can by focussing its resources on the thing it deems most important.