Start with the filling, since it will need to cool and possibly chill. Whisk the sugar, flour, milk, and coconut milk together in a small saucepan and set it over medium heat. Heat the mixture while whisking constantly until it comes to a simmer. After a minute or two of simmering, it should thicken to a pudding-like consistency. Remove the pot from heat and let it cool completely, about 1 to 2 hours, giving it a whisk every so often or covering it directly with plastic wrap to prevent a skin from forming.
Make the cakes while the filling mixture cools. Start by preheating the oven to 350°F and lining a couple of baking sheets with parchment paper.
Stir the ⅓ cup non-dairy milk together with the ground flaxseed in a large mixing bowl. Let the mixture sit for about 5 minutes, while you combine the dry ingredients. This is your flax egg.
Whisk the flour, cocoa powder, espresso powder (if using), baking powder, baking soda, and salt together in a large mixing bowl. Set it aside.
Add the butter, sugar, and vanilla extract to the bowl with the flax egg. Use an electric mixer at high speed to cream the ingredients together until fluffy, about 30 seconds to 1 minute.
Turn the speed of the mixer down to low, then slowly drizzle in the ½ cup of non-dairy milk with the mixer running.
Beat the flour mixture into the wet ingredients, adding about a third at a time and beating until fully combined. The batter will be thick and fluffy.
Drop the batter in rounds, about 2 tablespoons each, on the baking sheets, leaving at least 2 inches between them. You can bake the cakes in batches if they don't all fit on your baking sheets.
Bake the cakes for 13 to 15 minutes, until they're puffy and set. Test them for doneness by touching the top of one with a finger — it should feel set and spring back very slightly. If it stays collapsed, give the cakes a few minutes more.
Place the baking sheets on cooling racks when they come out of the oven. Let the cakes cool for about 5 minutes, then remove them from the baking sheets and transfer them directly to the racks to finish cooling.
Once the filling mixture has fully cooled, you can finish making the filling. Start by creaming the vegan butter, shortening, and vanilla together in a large mixing bowl. Beat in the cooled, cooked flour mixture, adding a bit at a time until the mixture is thick and creamy. If the mixture seems too loose to fill the cakes, cover the bowl and chill it for 30 to 60 minutes.
Spoon or pipe about 2 tablespoons of the filling onto the underside of one of the cakes, then top it with a second cake, sandwiching the filling between them. Repeat the process for the rest of the cakes.
Chill until ready to serve, or enjoy immediately.