-
Notifications
You must be signed in to change notification settings - Fork 207
feat(preact): add native support for preact #321
Conversation
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.
This is so good! Thank you so much for this work! I'll want to do a pre-release of this before merging just to make sure we're good to go. I'll let you know when I've done that. Thanks again!
.vscode/settings.json
Outdated
@@ -0,0 +1,3 @@ | |||
{ |
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.
Could you add this file to the gitignore? I don't like editor-specific settings in my repositories 😀
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. I need this file because my prettier rules are different and they're applied on each save. I'll keep it only in my fork.
other/preact.package.json
Outdated
@@ -0,0 +1,19 @@ | |||
{ |
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.
What's this for?
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.
package.json
file needs to be present in preact
folder since node.js looks into it to figure out which file to import. This file is used as a blueprint for it. Perhaps I could use main package.json file for this as well 🤔
I'm not familiar with preact or it's typings, but have you tested that this works, seems like there's a reasonable chance you'll get type failures with the react typings conflicting with preact ones. If this is a problem I think #320 should improve the situation. I'm unlikely to be able to spend much time looking into how the typings play with preact this week, but love the idea that the typings can be shared ❤️. Is there something like create-react-app for preact I can give this a quick spin? |
I've published this as the next beta!
Please try it out and let me know whether it works. |
@luke-john there's preact-cli but it contains a lot of packages, including Apart from that everything seems to work. Here's a playground that uses beta umd build. |
Thanks for that @marzelin. I think a nice way to solve this could be to have a file which re exports aliases of the react interfaces used by the typings. And then as part of the copy step for preact replace that file with one that has the preact equivalents. |
Codecov Report
@@ Coverage Diff @@
## master #321 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 10 10
Lines 172 174 +2
Branches 47 48 +1
=====================================
+ Hits 172 174 +2
Continue to review full report at Codecov.
|
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.
This is looking pretty good! Just another question :)
src/__tests__/preact.js
Outdated
beforeEach(() => { | ||
process.env.PREACT = true | ||
jest.resetModules() | ||
jest.mock('react', () => ({})) |
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.
Why is this necessary? Should it be: jest.mock('react', () => require('preact'))
instead?
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.
Yeah, I've added preact
as a dev dependency after all. Good idea 👏
package-scripts.js
Outdated
'build.umd.main.preact.tiny', | ||
'build.umd.min.preact.tiny' | ||
), | ||
copy("'package.json' 'preact'") |
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.
Hmmm... What does this do exactly?
I'm a little confused about the build process. When everything's finished, what are we left with?
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.
It creates a directory preact
in which the are all builds for preact as well as a copy of package.json
from the root directory. No typings at this time since current type definitions are react-dependent.
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 see! So, someone using the package would do:
import glamorous from 'glamorous/preact'
Is that right? That makes good sense. For downshift
I push everything into the dist/
and have .preact
filename, but I think I like this better. Thanks!
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 think that I want 2 more things before I merge this:
- A PR on the website to document how to use preact (bonus points if it includes a reference to using babel-plugin-module-alias to alias
glamorous
toglamorous/preact
and/or the webpack method) - One more beta release and some users verifying that it works properly.
This is so awesome. Thank you so much for putting all the work into this!
package-scripts.js
Outdated
'build.umd.main.preact.tiny', | ||
'build.umd.min.preact.tiny' | ||
), | ||
copy("'package.json' 'preact'") |
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 see! So, someone using the package would do:
import glamorous from 'glamorous/preact'
Is that right? That makes good sense. For downshift
I push everything into the dist/
and have .preact
filename, but I think I like this better. Thanks!
I'm working on this right now. I want to add kcd-utils to this project, so I'm just going to stick that in as part of this PR :) |
I literally spent all day on this 😂 But I think I've finally got it working a great way. Thank you for all your work on it @marzelin! |
Ok! I'll merge this and the docs PR as soon as I get one person to confirm that this works with preact-cli:
|
Not quite there. I just tested it and something's messed up. Should be a quick fix... |
Awesome! I've verified that import glamorous from 'glamorous/preact' 🎉 |
Tweeted. Sorry, I couldn't find your twitter handle :-/ Thanks so much!! |
Thanks so much for your help! I've added you as a collaborator on the project. Please make sure that you review the CONTRIBUTING.md and other/MAINTAINING.md files (specifically the bit about the commit messages and the git hooks) and familiarize yourself with the code of conduct (we're using the contributor covenant). You might also want to watch the repo to be notified when someone files an issue/PR. Please continue to make PRs as you feel the need (you can make your branches directly on the repo rather than your fork if you want). Thanks! And welcome to the team :) |
Awesome 🎉. Thanks @kentcdodds |
What: Adds out-of-the-box support for
preact
Why: Even though
glamorous
can be used inpreact
project, there are a few issues:preact
but invalid inreact
.preact-compat
is required to be able to useglamorous
How:
Build process creates preact directory that stores files dedicated for this library. To use them one needs to import glamorous from glamorous/preact.
preact
files differ from normal files in a following way:PropTypes
are neutralized (preact
doesn't use them) andChildren
polyfilled in ./react-compat.react
imports are replaced withpreact
(at build time).Other changes:
react
is removed from peerDependencies in package.jsonA shim of package.json is added to
preact
dir (at build time) to allow for importing files from there.typings
folder is copied to preact folder to provide type definitions fortypescript
closes #85
Checklist: