Skip to content

build(extension): Introduce our own module externalization logic for JavaScript entry points #14

@rekmarks

Description

@rekmarks

Like most bundlers, vite is extremely clever. It aggressively optimizes everything it touches, which means that cannot let it touch modules like ses and @endo/lockdown. As it turns out, getting vite to ignore a specific module is more difficult than it should be. In #8, I tried relying on importing our "endoify" shim at the top of our TypeScript entry point files. This worked, but in #11 I observed vite "optimizing" the import order such that modules that need to run under lockdown were imported before lockdown was called by our shim.

In #11, I'm taking the approach to manually insert a <script src="endoify.mjs" /> in the correct place in our HTML files, which appears to be the surest (only?) way to accomplish what we want. However, background.ts doesn't have a corresponding HTML file, and it remains at risk of being destructively optimized. Therefore, we should expand on my work in #11 to introduce our own module externalization logic for JavaScript entry points. I recommend taking a similar approach that I took to HTML files, i.e. writing in the import statements at the beginning of the relevant file(s) at the last possible moment.

Metadata

Metadata

Assignees

Labels

choreNot a feature, not documentation, but something we still have to do.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions