-
Notifications
You must be signed in to change notification settings - Fork 651
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
Added es build, which will get beneficial for es2015 modules aware bu… #77
Conversation
Thanks for this! There is a bit of an issue as is. The |
c2d13ca
to
78ee3e7
Compare
No worries, I've got u covered :) ! Ive just ammended the PR, please take a look. Such structure, although slightly inconvenient ( |
Is there a reason we can't copy the |
we cannot support also i aint sure what |
I'm less concerned about that I think, its still the more uncommon case. Eventually we can flip it. The package.json in the root is the one being published, tho the |
Interesting... I wonder if a separate |
I think this only bring more confusion to the table, especially for newcomers. A single package works out of the box for both commonjs and es consumers - it also enables easier migration paths from i.e. webpack1 to the webpack2+. Personally I wouldnt vote for this one. Personally puting Let me know what you decide that should be done and I'll adjust the PR. |
I'm fine adding this, but we need to add it the lib directory per my comment above :) I don't want to maintain a package.json for each file |
Any comments regarding concerns raised here? |
I think their reasonable concerns! I don't think think having folks cherrypick from an |
Ok, I will rebase and adjust the PR soon. |
c53cf80
to
7d7721c
Compare
@jquense Rebased and it should work. However your I don't think this release-script was designed with multiple entry points in mind and personally I think you'd be better without it, but that's your choice. Let me know if everything looks ok :) |
@jquense friendly 🏓 :) |
@silvenon I see you are active lately here, so maybe u'd find some time to comment on this one? 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have experience with ES builds yet, so I want to thread lightly.
Why wouldn't import Transition from 'react-transition-group/Transition'
work if we place es
inside lib
?
package.json
Outdated
"build": "rimraf lib && babel src --out-dir lib && npm run build:dist && cp README.md LICENSE ./lib", | ||
"build": "rimraf lib && npm run build:cjs && npm run build:es && npm run build:dist && cp README.md LICENSE ./lib", | ||
"build:es": "cross-env BABEL_ENV=es babel src --out-dir lib/es", | ||
"build:cjs": "cross-env BABEL_ENV=cjs babel src --out-dir lib", | ||
"build:dist": "rimraf lib/dist && webpack && NODE_ENV=production webpack -p", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe prepend cross-env
to NODE_ENV=production
as well, now that we have it installed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure thin, gonna apply this change when we agree on other stuff (would like to make a single, bigger change than multiple small ones)
package.json
Outdated
@@ -3,11 +3,14 @@ | |||
"version": "2.3.0-beta.0", | |||
"description": "A react component toolset for managing animations", | |||
"main": "lib/index.js", | |||
"module": "es/index.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this shouldn't be lib/es/index.js
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, now I pieced it together, it should be es/index.js
because lib
gets published as root.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, although IMHO publishing lib
is obscure and personally I would advocate for removing this and just publish normally pkg root + filter files with "files"
entry in package.json
"add-module-exports", | ||
"transform-object-assign", | ||
["transform-react-remove-prop-types", { "mode": "wrap" }] | ||
"./.babelrc.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm so glad that you switched to .babelrc.js
because I don't trust Babel's env
, plus it causes duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😉 I never have trusted babel's env either, I'm rly glad that I have found this neat trick 😀
Problem is that thing like The only way to hint bundlers to chose other file for such import is to make Whole algorithm can be found here (this doesnt consider "module" at all, for now "module" is "bundlers thing"). Don't want to advertise my article, but well... I've written it for a purpose - to explain all this craziness, so I encourage you to read it (click). |
Thanks for explaining it so well! These additional I'll take some time to study your blog post and see how we can make all this work with our release process. |
Lib as root approach gives more natural “deep” imports, otherwise users would have to use react-transition-group/lib/Transition. But as I said the same thing can be achieved with additional package.json files (just pointing out the possible reason behind lib as root approach) |
And ofc - this shouldnt be a breaking change for the users in any way :) |
I mentioned above that managing a bunch of additional package.json files is not something i really want to do, even tho they can be generated, less is more when it comes to build scripts. If someone wants to do the work there and can produce some reusable, small thing we can maybe stick in it's own package i'd be open to it, since it is a nicer experience, but otherwise i want to side on not having a lot of bespoke builds since i work on a lot of stuff We do publish lib/ as the root for cleaner imports, since the recommended approach, even with esm builds, is cherry-picking, since tree-shaking is an imperfect optimization |
Sure, can work on that 😉
With |
@silvenon what's the status of this? Is there anything I could do to help moving this forward? |
@Andarist thanks for pinging, I need to resolve conflicts if there are any and check for myself if this works correctly, maybe add a test if possible. I guess I'm still insecure about my knowledge in types of JavaScript modules so I don't want to merge something breaking, even though I trust that you know and it's really not a lot of code. It would help if you could tell me how to test manually whether this works. Is it enough to set |
mjs way will prevent loading esm from module field in react-lifecycles-compat. Webpack is very opinionated about this. |
@TrySound could u elaborate? Preferably with example |
From what I see package with module field (like material ui in the future) will prefer main field over mjs. Package with mjs (like this one) will prefer main field over module field (in case of react-lifecycles-compat). This makes mjs quite unusable since in most cases you get just cjs. |
I personally don't care a lot because my production bundler is rollup. |
Wepback will resolve any mjs file over js given how it's extensions are set for default. What it won't do tho is interop with cjs pretending to be esm tho, it's mjs parsing is strict which means any import that's not mjs is considered to be cjs and can only have default imports. This conflicts with webpacks other resolution logic which prefers the module entry to main. It's all sort of a mess for interop, but webpack is trying to do no harm by implementing mjs logic not to spec or out of line with what node is doing, to help prevent longer term fragmentation |
To be slightly cleaerer mjs files in webpack will only consider other mjs files to be esm modules, not esm in .js files |
O damn, this is is a mess then - packages have and will have all sort of dependencies and it's IMHO impractical to require each dependency to use I would personally be in favour of not using |
Yeah sorry @Andarist i realize that I did all this exploration into how this works with other of my own packages and didn't follow back up here. Let's move to the nested package.json route and get something out? Care to take that on? |
Yeah, sure! I think @TrySound might have wanted to do that too, could you confirm Bogdan? If you are not going to work on this one I'll probably get to it in few days. |
Sure, I can do it too. |
Ref reactjs#77 Upgraded semantic-release-alt-publish-dir to get correct module field processing jquense/semantic-release-alt-publish-dir@795af9d
BREAKING CHANGE: in environments where esm is supported importing from commonjs requires explicitly adding the `.default` after `require()` when resolving to the esm build Ref #77 Upgraded semantic-release-alt-publish-dir to get correct module field processing jquense/semantic-release-alt-publish-dir@795af9d
# [4.0.0](v3.0.0...v4.0.0) (2019-04-16) ### Features * support esm via package.json routes ([#488](#488)) ([6337bf5](6337bf5)), closes [#77](#77) ### BREAKING CHANGES * in environments where esm is supported importing from commonjs requires explicitly adding the `.default` after `require()` when resolving to the esm build
# [4.0.0](reactjs/react-transition-group@v3.0.0...v4.0.0) (2019-04-16) ### Features * support esm via package.json routes ([#488](reactjs/react-transition-group#488)) ([6337bf5](reactjs/react-transition-group@6337bf5)), closes [#77](reactjs/react-transition-group#77) ### BREAKING CHANGES * in environments where esm is supported importing from commonjs requires explicitly adding the `.default` after `require()` when resolving to the esm build
# [4.0.0](reactjs/react-transition-group@v3.0.0...v4.0.0) (2019-04-16) ### Features * support esm via package.json routes ([#488](reactjs/react-transition-group#488)) ([6337bf5](reactjs/react-transition-group@6337bf5)), closes [#77](reactjs/react-transition-group#77) ### BREAKING CHANGES * in environments where esm is supported importing from commonjs requires explicitly adding the `.default` after `require()` when resolving to the esm build
# [4.0.0](reactjs/react-transition-group@v3.0.0...v4.0.0) (2019-04-16) ### Features * support esm via package.json routes ([#488](reactjs/react-transition-group#488)) ([6337bf5](reactjs/react-transition-group@6337bf5)), closes [#77](reactjs/react-transition-group#77) ### BREAKING CHANGES * in environments where esm is supported importing from commonjs requires explicitly adding the `.default` after `require()` when resolving to the esm build
# [4.0.0](reactjs/react-transition-group@v3.0.0...v4.0.0) (2019-04-16) ### Features * support esm via package.json routes ([#488](reactjs/react-transition-group#488)) ([6337bf5](reactjs/react-transition-group@6337bf5)), closes [#77](reactjs/react-transition-group#77) ### BREAKING CHANGES * in environments where esm is supported importing from commonjs requires explicitly adding the `.default` after `require()` when resolving to the esm build
…ndlers like webpack 2+ and rollup
IMHO this should also be cherry-picked to the
v1
branch.This will allow webpack3 to use scope hoisting on this package + ofc tree-shaking will become possible.