Spray a large microwave-safe mug (12-14 oz capacity) with cooking spray or lightly grease with oil to prevent sticking.
Add the flour, sugar, shredded coconut, baking powder, and salt directly to the mug. Stir with a fork until evenly combined and no lumps remain.
Pour in the coconut milk, oil, vanilla extract, and coconut extract if using. Stir gently just until the flour is incorporated and the batter is smooth, about 10-15 seconds. Do not overmix.
Fold in the crushed pineapple, distributing it evenly throughout the batter.
Microwave on high power for 60-90 seconds, checking at 60 seconds. The cake is done when the top looks just set and a toothpick inserted in the center comes out with only a few moist crumbs.
Let the mug cake cool for 30 seconds to allow the texture to set properly.
Top with toasted coconut flakes and serve immediately while warm. Add whipped cream, ice cream, or extra pineapple if desired.