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

[feat]: Browser compatible ESM build output? (or there is a better practice i missed?) #62

Open
nailchu opened this issue Mar 10, 2025 · 1 comment

Comments

@nailchu
Copy link

nailchu commented Mar 10, 2025

A clear and concise description of what the feature is

I noticed that there are three configurations in the rollup configuration file rollup.config.mjs , one in commonJS format, one in ES module format, and one IIFE.

When I tried to use this sdk in a frontend project (like Vue or React) as what the README said, since CommonJS and ES Module have browser: false, preferBuiltins: true configured, this means they will prioritize using node modules, causing browser compatibility issues. (For details, please refer to issue #61 .)

Do you plan to add a browser-compatible ES Module to the compiled output formats? Or I missed a better practice? Or I should just turn to RESTful api?

Why should this feature be included?

I think using a <script> tag in Vue/React project is not appropriate.

Please provide an example for how this would work

When using import { strapi } from '@strapi/client'; it actually use bundle.mjs which prefer built-in modules.
I tried to modify rollup.config.mjs and built a browser compatible ES module (output like bundle.browser.esm.js).

Image

Then I modified Vite config of my own project to use the new file.

Image

Then everything goes well.

@Convly
Copy link
Member

Convly commented Mar 11, 2025

Hey, thanks for opening this and for your research.

We're going to add that to our backlog and investigate how we can provide a working solution for every platform.

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

No branches or pull requests

2 participants