Comments (5)
Hello @ruanyl!
I don't think you need the commonjs plugin for your use case since you are using the bundle: true
option without externals.
Esbuild itself should bundle commonjs dependencies and export React as default specifier. In fact, at the end of the out.js file I can see the statement:
export default require_react();
Do you have a different output?
from rna.
@edoardocavazza Thanks for your reply :) I probably had some misunderstandings of the use-case of commonjs plugin.
Yes, I have React exported as default, but the problem with esbuild forma: 'esm'
is it didn't create export
for named exports, such as useCallback, useMemo
, etc.
What I'm trying to do is compile React to native ESM so that I can use it directly in the browser without bundling it.
from rna.
You understood it correctly, but there are were two problems here.
The first one is was a bug 😅 I should have addressed it with the 0.12.39 version. Thank you for reporting!
The second one is a "design" choice: the commonjs plugin can transform module.exports.something
to export const something
, the problem here is that the React entrypoint exposes the whole module to module.exports
.
AFAIK, even Node loads this kind of modules using default specifier, so I intended the plugin this way.
BUT, you can try to change the entrypoint to "./node_modules/react/cjs/react.development.js"
, which correctly assigns named references to the module.exports
.
from rna.
Hi @ruanyl , have you managed to create an ESM-based React package? Can we close this issue?
from rna.
@edoardocavazza Yep, thanks for the help, closing now :)
from rna.
Related Issues (20)
- wtr-mocha-reporter - when web-test-runner run in watch mode does not finish running tests HOT 2
- Wrong path for CSS assets HOT 2
- Can't use assets in a SPA without proxy HOT 2
- bad path separator for assets HOT 3
- [esbuild-plugin-html] Load style files without script HOT 4
- [esbuild-plugin-alias] Align with esbuild builtin alias management HOT 1
- esbuild-plugin-html does not use the original directory of the source file HOT 6
- esbuild-plugin-meta-url only transforms node_modules? HOT 1
- document how to interop normal esbuild plugin with esbuild-rna plugin HOT 2
- Unable to specify an output directory with esbuild-plugin-meta-url HOT 3
- Feature Request: Single Page Application support for the HTML plugin. HOT 1
- feat: [esbuild-plugin-html] Support esbuild `publicPath` HOT 1
- SyntaxError: Identifier '__filename' has already been declared HOT 3
- Weird behavior when not using `hash`
- SourceMapNode is not a constructor HOT 3
- Minimize html
- Error with `require-resolve` HOT 2
- esbuild-plugin-html only watches the HTML file HOT 7
- React example? To replace react-scripts build HOT 10
- Windows bug in `esbuild-plugin-html` - Not escaping backslashes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rna.