Caramelize the Onions:
Melt the butter in a large pot over medium-low heat. Add the sliced onions and cook slowly, stirring occasionally, for 30-40 minutes until the onions are golden brown and caramelized.
Simmer the Soup:
Once the onions are caramelized, add the wine (if using) and simmer for 2 minutes. Pour in the beef stock, add bay leaves and thyme, and bring the soup to a simmer. Let it cook on low heat for 30-40 minutes to develop the flavors. Add salt and pepper to taste.
Prepare the Croutons:
Preheat the oven to 350°F (175°C). Brush the baguette slices with olive oil and toast them in the oven for about 10 minutes, or until crispy.
Assemble the Soup:
Ladle the soup into oven-safe bowls. Place a toasted baguette slice on top of each bowl, then generously sprinkle with grated Gruyère cheese.
Broil the Cheese:
Preheat the broiler. Place the bowls under the broiler until the cheese is melted and bubbly, about 3-4 minutes. Serve hot.