Skip to content

Conversation

zdunecki
Copy link
Contributor

@zdunecki zdunecki commented Aug 9, 2025

This PR

  • Adds a global (IIFE) build for the web for GrowthBook and LaunchDarkly

Notes

It's a concept only, I'm not quite sure if OpenFeature Community is likely to follow this idea. If so, I'll update this PR by improving a build process since this repository has a special build system.

How to test

  1. Run npm run build and ensure dist/global/index.js is generated for GrowthBook and LaunchDarkly web client

Motivation

Trying to load OpenFeature as a first dependency before browser will resolve any modules.

@zdunecki zdunecki requested review from a team as code owners August 9, 2025 14:40
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @zdunecki, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

I've introduced a new feature that provides global, Immediately Invoked Function Expression (IIFE) builds for the web client providers, specifically for GrowthBook and LaunchDarkly. The primary motivation behind this change is to enable OpenFeature to load as a foundational dependency in web environments, ensuring it's available before other modules are resolved by the browser. This is currently a conceptual implementation to explore its viability.

Highlights

  • Global IIFE Builds: Introduced a new build process using Rollup to create global (IIFE) bundles for the GrowthBook and LaunchDarkly web client providers.
  • New Build Scripts: Added a 'build:global' script to the package.json of both GrowthBook and LaunchDarkly client providers, enabling easy generation of these new global builds.
  • Rollup Configuration: Configured Rollup to handle external dependencies and map them to global variables (e.g., OpenFeature, growthbook, LDClient) for the IIFE output.
  • Minified Build Variant: Included minification for the LaunchDarkly global build using @rollup/plugin-terser, optimizing the output size.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a global IIFE build for the GrowthBook and LaunchDarkly web client providers, which is a great addition for users who want to include these providers via a simple <script> tag. The implementation uses Rollup and looks solid.

My main feedback is to ensure consistency between the two new build configurations. The LaunchDarkly provider build generates both a standard and a minified bundle, which is excellent. I've suggested applying the same pattern to the GrowthBook provider for completeness and better usability.

Comment on lines +1 to +26
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import esbuild from 'rollup-plugin-esbuild';

export default {
input: 'src/index.ts',
output: {
file: 'dist/global/index.js',
format: 'iife',
name: 'GrowthbookProvider',
globals: {
'@openfeature/web-sdk': 'OpenFeature',
'@growthbook/growthbook': 'growthbook',
},
sourcemap: true,
},
external: ['@openfeature/web-sdk', '@growthbook/growthbook'],
plugins: [
commonjs(),
resolve(),
esbuild({
target: 'es2017',
tsconfig: './tsconfig.json',
}),
],
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with the launchdarkly-client provider, it would be beneficial to also generate a minified version of the global build. This improves usability for consumers who want to use a smaller file in production.

You can update this file to produce both bundled and minified versions. Also, remember to add @rollup/plugin-terser to the devDependencies in libs/providers/growthbook-client/package.json.

import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import esbuild from 'rollup-plugin-esbuild';
import terser from '@rollup/plugin-terser';

const bundle = {
  input: 'src/index.ts',
  output: {
    file: 'dist/global/index.js',
    format: 'iife',
    name: 'GrowthbookProvider',
    globals: {
      '@openfeature/web-sdk': 'OpenFeature',
      '@growthbook/growthbook': 'growthbook',
    },
    sourcemap: true,
  },
  external: ['@openfeature/web-sdk', '@growthbook/growthbook'],
  plugins: [
    commonjs(),
    resolve(),
    esbuild({
      target: 'es2017',
      tsconfig: './tsconfig.json',
    }),
  ],
};

export default [
  bundle,
  {
    ...bundle,
    output: {
      ...bundle.output,
      file: 'dist/global/index.min.js',
    },
    plugins: [...bundle.plugins, terser()],
  },
];

@lukas-reining
Copy link
Member

Hey @zduneckim,
I will have a look at this tomorrow :)
Please also sign-off the commit for this, as with the other PR.

Signed-off-by: Patryk Zdunowski <zdunekhere@gmail.com>
Signed-off-by: Patryk Zdunowski <zdunekhere@gmail.com>
@zdunecki zdunecki force-pushed the feat/web-global-build branch from c0d0169 to b683b6c Compare August 11, 2025 15:40
@beeme1mr beeme1mr requested a review from lukas-reining August 29, 2025 15:31
@zdunecki
Copy link
Contributor Author

@lukas-reining

What you think about this? As I said before, it's a concept only - let me know if idea is fine for you. If so, I'll try to fix test issues + find a better build solution and apply DRY.

Best,

@lukas-reining
Copy link
Member

Hey @zdunecki sorry for the delay!
I think this is a good addition!
We should consider adding it to the generators if everyone is in favor: https://github.com/open-feature/js-sdk-contrib/blob/main/tools/workspace-plugin/src/generators/open-feature/index.ts#L166
It seems like it might be be enough to declare any vendor SDK as external and otherwise have a generic esbuild config?

@zdunecki
Copy link
Contributor Author

zdunecki commented Sep 7, 2025

@lukas-reining
No worries. Sounds cool, so if I'm back to contribution, I'll implement that.

Can't say when, but I'll try soon.

Best,

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

Successfully merging this pull request may close these issues.

4 participants