Comments (3)
the main.js also exported a function that i cannot use from Node.js it should've been exported.
The reason why this wasn't working before was because esbuild actually generated output in the IIFE (immediately-invoked function expression) format, not the CommonJS format that node uses, since I've been focusing on running code in the browser.
I added a new --format
flag to control the output format and added support for the CommonJS output format. You can enable that with --format=cjs
. However, if you want this to run in node you'll probably want to use --platform=node
which automatically implies --format=cjs
. Bundling with --platform=node
enables referencing builtin node libraries and if you use any node modules that have both browser and node variants, switches esbuild over to bundling the node variants.
(Another comment: the bundle is pretty big compared to what rollup produces for the code i mentioned do we really need all that stuff?)
I assume you're talking about the extra module loading code esbuild sticks at the top. No, that stuff isn't necessarily needed. I'm trying to have esbuild support bundling both ES6 and CommonJS modules instead of something like Rollup, which only natively supports ES6 modules. That extra stuff is for CommonJS support.
I'm working towards a state where that extra stuff is stripped out when it's not needed. Believe me, it bugs me too. But I haven't yet done the additional work to detect when it's not needed and strip it away. I'll definitely get to this at some point.
(Mostly as a reminder for me later) I recently made some progress towards this state by rearranging how the bundle is structured so that helper code is now in multiple top-level functions instead of in a single multi-purpose function nested inside a closure. The next step is to detect which of those helper functions are unused and strip the unused ones away, which will only leave the ones that are actually needed, if any. I also need to detect if all code reachable from the entry point is valid ES6 and, if so, skip embedding the code inside a CommonJS module map.
from esbuild.
@evanw any ideas about this? I also can't use react with multiple files it generates broken code for the importing logic.
from esbuild.
I tried --platform=node
and didn't work but explicit --format=cjs
did the job, thanks!
from esbuild.
Related Issues (20)
- Constant folding doesn't simplify inequalities
- Cannot implement import attribute `with { type: "external" }` HOT 2
- css nesting lowering doesn't work when both a pseudo element selector and a class selector is used HOT 1
- Different bundle output between macOS and Ubuntu HOT 1
- TestGradient with "in_hsl_longer_hue" currently fails on ppc64le and s390x HOT 6
- Unable to resolve files with CLI but works from file config HOT 3
- Q: Does the esbuild file loader support changing the file extension? HOT 3
- Are we implementing node esm/cjs interop correctly HOT 3
- esbuild fails to bundle MUI (Material UI) HOT 4
- Is there a way to drop only specific types of console logging ? HOT 1
- empty enum got undefined after compilation
- Experimental class decorator will degrade private fields. HOT 2
- Unreachable switch statements become 'skeletons' when minified instead of being removed
- Swagger won't load after building the app HOT 3
- Transform resolving always true/always false expressions HOT 4
- esbuild messes with path after plugin does his job HOT 2
- Bug: YarnPnP cannot resolve drive letter correctly
- OpenBSD arm64 support HOT 5
- add an optional cache and `exclude` option to the `onResolve` plugin hook HOT 1
- Injecting code into bundled dependency with iife format HOT 3
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 esbuild.