Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module instead of IIFE provided builds #1002

Open
chaseWilliams opened this issue Feb 25, 2025 · 4 comments
Open

Module instead of IIFE provided builds #1002

chaseWilliams opened this issue Feb 25, 2025 · 4 comments
Labels
feature Request a new feature

Comments

@chaseWilliams
Copy link

Description

Our team can't use the IIFE build because they do not work in salesforce LWC, so instead we've just been internally building module builds with faro-web-sdk instead

Proposed solution

It would be nice if you could do something like this:

npm i @grafana/faro-web-sdk
npx faro-web-sdk build -- --output-format=module
echo ./node_modules/@grafana/faro-web-sdk/packages/web-sdk/dist/bundle/...

Context

The iife distribution does not work when either manually trying to load it as a <script> or when using loadScript, likely due to Salesforce's locker security constraints. This is because the Lightning Locker prevents third party scripts from setting global variables, which means even though the sdk loads, it isn't actually accessible at all for initializing in the application code.

@chaseWilliams chaseWilliams added the feature Request a new feature label Feb 25, 2025
@chaseWilliams
Copy link
Author

Specifically this is how I changed the rollup.config.base.js to get a working build for us

-      file: `./dist/bundle/${module.bundleName}.iife.js`,
-      format: 'iife',
+      file: `./dist/bundle/${module.bundleName}.module.js`,
+      format: 'module',

@codecapitano
Copy link
Collaborator

Hey @chaseWilliams that's actually a nice enhancement.

Another option would be to include a module build by default.
Currently Faro includes cjs and esm builds and the IIFE bundle by default so users don't need to compile it themselves.

Wdyt about that option?

@chaseWilliams
Copy link
Author

I think that sounds good, are you talking about also distributing a module build on the CDN as well? @codecapitano

@codecapitano
Copy link
Collaborator

Hey @chaseWilliams yes exactly.
We would have both, CDN and a sub dir in the NPM package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Request a new feature
Projects
None yet
Development

No branches or pull requests

2 participants