Build variable to indicate "background" or "content" script?
Right now the only thing I can do to determine if a shared function is running in content or background is by checking
"serviceWorker" in globalThis
which unfortunately is a runtime check. Is there a variable (documented or not) that exists in env that would make it so code can be tree shaken? e.g. if (process.env.PLASMO_BUILD_TARGET !== "background") { ... }
would allow the bundler to drop this branch if it's part of the background bundle.
This is largely so I can share utility code between content and background where it performs all of its work in background (content scripts using messaging to background). Right now because I have to use a runtime check, a bunch of never used in content scripts code is included in the content scripts bundles.0 Replies