In a 9-inch cast iron or oven proof skillet, melt the butter over medium heat. Add the sliced onions, half of the salt, the pepper, and the sugar if you are using it.
Stir to combine and cook until the onions are soft and deeply golden brown--about 25 minutes. Turn off the heat and add the vinegar. Stir to combine.
Transfer the onions to a large bowl and add the gruyere, mayonnaise and sour cream and stir to combine. Add the cooked bacon and stir. Transfer the mixture back to your pan and bake immediately, or allow the pan to cool and then put the mixture back in, cover it with plastic wrap and chill up to two days until ready to bake.
Bake 20 minutes until golden and bubbly. Serve hot with sliced, toasted baguettes or toast points.