🚀 Insert empty ESM export to ensure file is parsed as module
From discussions with the Chrome team, apparently using <link rel=preload> and pointing it at a script that's used as type=module will cause a double parse of the script. Once as a regular Script, and once as an ESM Module. Adding in an ESM export {} ensures that the file cannot be parsed as a Script (because export is only valid in ESM Modules), thus saving us from processing this file twice.
This means using <script src="foo.mjs"> without setting type=module will fail!
Funny enough the module/nomodule tests are failing with this PR.
Just for verification, did we confirm that terser and friends do not remove this export?
I tried on the terser website (and it stays), but not our actual dist output. After checking, it did remove it 🤦 .
Does this affect both v0.mjs and amp4ads-v0.mjs? I'm cool with this, but we need some time to fix the transformer since it still uses <script src=amp4ads.mjs. Can we hold on merging this if it affects amp4ads-v0.mjs?
Does this affect both v0.mjs and amp4ads-v0.mjs?
Yes.
Can we hold on merging this if it affects amp4ads-v0.mjs?
That's why you're included on the PR. But this is the reason I opened the CL yesterday, we're trying to optimize our ESM code and that requires treating it like a real module.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.