-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Why don't you add ES5 transpiled code to your modules for browsers? #446
Comments
I looked through the
I wonder about tooling:
|
I also faced this problem (using a library in the browser that is written in ES2015) when using jspm: jspm/registry#985.
This way, we don't have to specify which dependency is written in ES2015. I don't exactly know how this could be applied to Webpack as I'm not familiar with it. |
While most of my modules also work in the browser, I make them mainly for Node.js. I love how dependencies in Node.js just work without having to resort to a bundler, compile-step, and a huge config file. Just I think this problem should be solved by Babel or bundlers like webpack. One solution would be to automatically check the "engine" field in the package.json of dependencies and decide which dependencies to transpile. Babel has pretty good caching, so it would only transpile the ES2015-written dependencies once per version. |
Not that I'm aware of. People more familiar with webpack might be able to answer the second question. |
@TheLarkInn @hzoo Could we maybe take this discussion and facebook/create-react-app#1125 to a new Babel or webpack issue? |
@sindresorhus FWIW this was also discussed a bit in w3ctag/polyfills#6 and I think we came to similar conclusions as you. There maybe ought to be some kind of specification in |
So yeah, as webpack'y answer would specify that bundling sources are good and that leveraging tools like babel-preset-env to transpile based on target only specific features is a good start. However I know that's not a all encompassing solution for everyone. |
I understand your rationale and that's legit and fine! Please consider documenting this fact clearly in your modules, so people don't waste your and their time opening issues about it. @TheLarkInn is there any particular recommended way to detect and transpile ESM in webpack without setting up ugly include lists for |
The Node.js version I target is documented in package.json in every module I maintain: https://github.com/sindresorhus/camelcase-keys/blob/fa7d9883e8ffb6d98b8d04533f2e0b342c7d35ee/package.json#L12-L14 I'm not going to document anything more than that as I don't target the browser. You're free to use my modules in the browser, but you're on your own. Ideally |
Yeah, I just saw you came up with the same idea a while ago. :) I'll pay attention to the engines field next time. |
I'm seriously considering forking |
Or |
@SamVerschueren would appreciate if we could work together on something instead of just making a fork. I asked about this earlier https://twitter.com/left_pad/status/838028823572725761 and seems like although a lot of people are in favor some really didn't want it. I would be cool with a pkg that just enables env by default with a polyfill |
I totally agree with the fact that compiling a module for browsers is often a huge mess and a lot of headaches, there are so many different tools with complex configurations that you easily get lost. I was tired of that, so I created Lyo, an opinionated compiler that doesn't need any configuration to work. In fact, Lyo is nothing more than a wrapper of other tools, the same way XO is an ESLint wrapper with pre-defined rules. With Lyo installed globally, transpiling your module for browsers shouldn't be harder than running a single command: And because you cannot expect every maintainer to provide transpiled code, Lyo also works with other people's modules. If you need a transpiled version of query-string for example, just run So, I don't think I'll make Sindre change his mind about the idea of providing transpiled code with his modules, but I hope it will help:
Have a nice day 👍 |
Create React App 2.0 is out with transpilation of dependencies 🎉 |
Noticed more and more questions about adding ES5 files to your projects. The reason is off course that we started dropping support for older Node versions. So I expect more questions in the future. Same situation as #439. I want to be able to link your answer so that people don't have to take me on my word when I answer and close.
The text was updated successfully, but these errors were encountered: