Comments (5)
Would you mind elaborating what we'd have to do to support that?
All we do right now, is generating the ES build with Babel, haven't really dug into additional stuff though.
Would love to make Fela ESM-first!
from fela.
Happy to go into details in another channel since it's harder to explain in prose. It took myself around 1-2 weeks to fully understand the difference between faux-ESM vs ESM. Build tools (rollup
, microbundle
, webpack
, babel
) that generate a dist/index.module.js
file isn't equivalent to being an actual ESM.
tl;dr
A real ESM module is based on the following specs:
"type": "module"
inpackage.json
(for Node to understand), and equivalently<script type="module" />
(for browsers to understand)- files ending with
.mjs
(Node-only)
Anything not following the above is faux-ESM, and happens to behave as ESMs only by nature of the build tools that support it. For example webpack
, rollup
, microbundle
conveniently process "module": "dist/index.module.js"
in package.json
to infer that the module is ESM. This is however not the standard spec, so a dependency on building/compiling is required to infer this as ESM.
If consumers are using build tools, it's not a big deal and these tools will handle reading the file as an ESM. It's the reason why build tools just work, because the ecosystem of consumers use these tools as well (e.g. CRA, Gatsby, Snowpack, almost every modern build tool).
A good way to test if a package is an ESM is to run it through node my-script.js
calling the source code that you are testing (This is also a good way to test if we are writing JS without the use of additional plugins, and that the code is just standard JS).
Refactoring to ESM is probably a big effort and very likely a breaking change to consumers, since you have to ensure your dependencies are also ESM-compliant. I came across this in fela
when I was authoring my package as an ESM, but realized that Fela is faux-ESM.
Not here to influence the direction of Fela but I think this ecosystem is great, and joining the movement of the broader JS ecosystem returning to standards will be exciting! It'll be a future of just shipping source code without compiling and building, and things just run (in Node, in browsers everywhere).
from fela.
The very fast way to make Fela ESM without rewriting the code (for the sake of being ESM-pure)
- Keep the current bundling/compiling
- In
package.json
, update
{
"type": "module",
"main": "es/index.js"`, // now points to the ESM
"exports": { // allows CJS/require consumers to still consume
"import": "./es/index.js",
"require": "./lib/index.js"
},
}
- Ensure all dependencies (if any) are ESM
- If you decide that Fela will never support CJS (it'll most likely be dead since browsers/Node will formally support ESM and ESM can support CJS), then you can also drop the
exports
field inpackage.json
in 2.
The expensive part is 3. since you do not have control over it and dependencies need to be (real) ESM for this to work. If an evaluation of the Fela ecosystem suggests that 3. is minimal, then there's a good chance of making Fela ESM-first! It would still mean a major breaking change, but the whole JS ecosystem is going through a disruptive phase with vibes from the Python2 to Python3 migration.
from fela.
Closing because it's not a huge issue but looking forward to formal ESM support without build tools in the future!
from fela.
What about it today? I see Fela tries to support esm, but it still is using CommonJS libraries such as "isobject".
Actually, the need for the isobject dependency is pretty questionable, but putting that to the side, what are the plans to support esm currently?
from fela.
Related Issues (20)
- react-fela providers only accept single element children HOT 2
- Use fela with ReactDOM.createPortal on a different window HOT 1
- fela-plugin-responsive-value doesn’t handle nested objects
- Fela doesn’t hydrate CSS custom properties HOT 1
- fela-plugin-multiple-selectors doesn’t extend styles
- renderStatic doesn’t handle nested objects
- Document targetDocument
- renderToNodeList not exported in react-fela/index.d.ts HOT 1
- Typescript plugin doesn't extend style definition HOT 5
- renderStatic not applying some plugins HOT 6
- Missing changelog for 11.5.x & 11.6.x HOT 2
- Rehydration of `&` selectors HOT 10
- Rules are mixing between components when we switch between pages. HOT 1
- Typescript interface for renderer configuration (IConfig) misses some options HOT 2
- Transform key as array ignored HOT 5
- [Feature] Add bindings for solid-js HOT 1
- Fail to set backgroundImage fallback value HOT 3
- Bug: no fela styles on saved page HOT 1
- react-native: no style export in useFela hook HOT 2
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 fela.