Add butter to a large pot or dutch oven over medium heat. Once the butter has melted, add the sliced onions, sugar, salt, and pepper. Stir well to coat the onions in the melted butter and evenly distribute the other ingredients.
Cook the onions, stirring occasionally, until softened and starting to turn a deep brown, anywhere from 45-60 minutes. The amount of time it takes to really caramelize the onions can depend on the size and type of your pot and the heat used, but it is best to take your time and use a lower heat so you don't burn the onions. If they seem to be burning, reduce the heat slightly, be sure to stir them well, and add a splash of water or beef broth. The onions should be caramelized to a deep, rich brown color.
While the onions cook, preheat oven to 400°F. Arrange sliced baguette pieces on a baking sheet. Once the oven is hot, toast the bread for 8-10 minutes until lightly golden and crisp.
Once the onions are fully caramelized, sprinkle the flour over them onions and stir well until the flour has been absorbed, about 30-60 seconds.
Add the ½ cup of white wine (or just ½ cup of the beef broth, if you want to make this french onion soup recipe without wine) and increase the heat to high heat. Use a wooden spoon to deglaze the bottom of the pot by scraping up any browned bits (called fond, which gives loads of flavor) until the onions are almost jam-like in consistency. Continue to cook until the wine has completely cooked down and evaporated to the point that there is no more liquid in the pot.
Add beef broth garlic, bay leaves, thyme, salt, and pepper. Stir well, then bring to a boil.
Once boiling, cover the pot with a lid. Reduce the heat to low and simmer for 20 minutes.
Set 6 oven-safe bowls on a baking sheet. Ladle the hot soup into the bowls, evenly distributing it, then cover each bowl of soup with slices of baguette, making sure they don't overlap. Sprinkle a generous amount of the gruyere and freshly grated Parmigiano Reggiano cheeses on top of the bread slices in each bowl.
Turn on the oven broiler and carefully transfer the baking sheet with the soup bowls to the oven under the broiler. Broil just until the cheese is melted and starts to bubble and toast. Serve immediately.