Feat/1101 iife content scripts#1158
Open
salmin89 wants to merge 4 commits intocrxjs:mainfrom
Open
Conversation
Add support for bundling content scripts as self-contained IIFE files. Content scripts named with .iife.ts extension are automatically detected and built as single files with all dependencies inlined. This is useful for: - MAIN world content scripts (chrome.scripting.executeScript) - Avoiding loader overhead - Single-file distribution The IIFE plugin uses Vite's library mode to build each .iife.ts file separately, producing a single bundled output per content script.
- Update manifest plugin to skip emitting .iife.ts files (handled by IIFE plugin) - Update content scripts plugin to skip IIFE type processing - Update dynamic content scripts plugin to auto-detect .iife.ts files - Add enforce: 'post' to dynamic scripts build hook for correct ordering
🦋 Changeset detectedLatest commit: 4f5d2ec The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
c9aa0b8 to
319d4ab
Compare
- Add unit tests for isIifeContentScript filename detection - Add E2E build test verifying IIFE output format and inlined imports - Add E2E serve test verifying .iife.ts files work in dev mode - Test both manifest-declared and dynamic (?script) content scripts
319d4ab to
0f729b4
Compare
Member
Contributor
Author
|
I'd love to see what @jacksteamdev thinks about this solution |
Contributor
Author
Initially when I tested 1102 it didn't do what I needed it to do. I see that you ended up updating the PR and got it working (I missed the update). I would say that this PR does the same thing as #1102 does, but also adds support for IIFE in the manifest (by naming .iife). I just added a comment to your PR while testing it out: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey guys!
Full disclosure:
I used Agents to heavily assist with this PR. This feature is something we've needed at my company for a while, but I never had enough time to learn CrxJS enough to be able to it without help from AI. My strategy was to write tests to make sure we didn't break any existing functionality.
This feature would solve a number of open issues (some of which would need to accept the iife lifestyle)
#1102
#1101
#1152
#1119
The following below is what the AI generated to describe this PR.
feat: Add IIFE content script bundling
Summary
This PR adds support for bundling content scripts as self-contained IIFE (Immediately Invoked Function Expression) files. Content scripts named with the
.iife.tsextension are automatically detected and built as single files with all dependencies inlined.Motivation
When injecting content scripts into the
MAINworld usingchrome.scripting.executeScriptorchrome.scripting.registerContentScripts, ES modules are not supported. This requires content scripts to be bundled as IIFE files with no external imports.Previously, developers had to manually configure separate build steps or use workarounds. This PR adds first-class support for IIFE content scripts with zero configuration.
Usage
1. Manifest-declared content scripts
Name your content script with
.iife.tsextension:src/content/injected.iife.ts
manifest.config.ts
2. Dynamic content scripts (chrome.scripting API)
src/background.ts
Output
Regular content script (main.ts):
assets/main.ts-loader-xxx.js+ chunksIIFE content script (
main.iife.ts):src/content/main.iife.jsBenefits
.iife.tschrome.scripting.executeScript?scriptimports - Auto-detected for dynamic content scriptsTrade-offs
Testing