Comments (4)
How hard do you think it would be to make a module that works in both of these environments? Is it worth adding yet anther setting or should we just try to make the ES6 output UMD compatible?
Out of interest what is the platform you are targeting that requires UMD compat?
from emscripten.
How hard do you think it would be to make a module that works in both of these environments? Is it worth adding yet anther setting or should we just try to make the ES6 output UMD compatible?
Out of interest what is the platform you are targeting that requires UMD compat?
I don't think the idea that one module supporting both UMD and ESM can work, because reference to import
(eg. import.meta.url
) will cause an syntax error if not in ESM.
The reason why I want to distribute a UMD bundle is because of bundler compatibility. There are 2 reasons:
- A ESM module can import a CJS module and bundler can do this correctly; but it is very hard to import ESM in a CJS module.
- Currently some bundlers (Webpack, parcel, ..) will rewrite
import.meta.url
into static strings like"file:///path/to/build/time/file.js"
. This will make the Emscripten generated code not working.
As a library author, the best option for me is to offer 2 exports - one for UMD and one for ESM. This is why I created this issue.
from emscripten.
BTW it would be great if Emscripten can support generate multiple targets at one build (not only UMD/ESM). In my use case, I acutally need 4 targets:
- output.js (umd, ENVIRONMENT=web,webview,worker)
- output.mjs (esm, ENVIRONMENT=web,webview,worker)
- output.node.js (umd, ENVIRONMENT=node)
- output.node.mjs (esm, ENVIRONMENT=node)
I am currently using Regex to replace the code snippet in generated files in order to exclude Node.js outputs for web. This is very hacky and unstable because with the upgrade of emscripten the old regex may no longer work.
You may be interested in why I don't use default. Because default supports both web and node, right? The reason is the bundler again:
- Bundler is not happy with
await import("module")
even it is guarded by conditionisNode
. - Tree shaking is not working with the variable of
IS_ENVIRONMENT_NODE
from emscripten.
I would share a viewpoint from a library developer: some requirement above is not a problem of Emscripten, they are more like the problem of bundler. However, we cannot control or predict how users use bundler. If bundler has a bug or an unexpected behavior, we can track the bugfix but at the same time we need to workaround to offer user the out-of-box experience.
from emscripten.
Related Issues (20)
- ASYNCIFY and INCOMING_MODULE_JS_API HOT 3
- thread wasm64 HOT 2
- Multithreading worker issue HOT 3
- Improve support for keyboard input on mobile browsers HOT 4
- emcc/wasm-ld fails autoconf sanity check HOT 3
- Error after setting GL_UNPACK_ROW_LENGTH HOT 10
- emconfigure sets both, CROSS_COMPILE and CC to absolute path, which seems to fail with man projects HOT 2
- Dynamic linking broken in 3.1.57
- `alignof(long double) == 8` even though `sizeof(long double) == 16`—why? HOT 2
- `FS.stat` has inconsistent `[a/m/c]time` values in WasmFS HOT 4
- pthread workers fail to run when ENVIRONMENT=worker only HOT 8
- Component model support in Emscripten HOT 1
- --emit-tsd does not output function argument names HOT 2
- Can't preload files/shared libs in service worker due to lack of XHR [PR OPEN]
- isinf() can return -1 HOT 4
- missing FE_xx defines HOT 7
- Building failure after switching from 3.1.47 to 3.1.57 HOT 7
- Passing array of arrays to emscripten HOT 1
- --extern-pre-js no longer accessible in Workers HOT 1
- Operator Overloading Error in system/lib/libcxx/include/__algorithm/sort.h 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 emscripten.