💥 Native preact/compat alias using only NPM #3288
iamandrewluca
started this conversation in
Show and tell
Replies: 1 comment
-
Same effect should be simpler to accomplish with @preact/compat package. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm playing around to move to Preact in a
create-react-app
.In docs Preact says you need to alias
react
andreact-dom
topreact/compat
.create-react-app
not allows aliases by default, you need to eject or usecraco
or `react-app-rewiredThen I remembered that NPM allows you to install a package under any name, using:
And I ralised that
npm:
is just the protocol, and we can use other protocols, likefile:
Install Preact
NPM Alias
react
andreact-dom
topreact/compat
After install, remove
compat
types so TypeScript can consume@types/react
npm set-script postinstall "rm node_modules/react/src/index.d.ts"
Boom 💥 -33.8KB from bundle
There is no need to configure your build system at all.
And it just works!
PR: roataway/roataway-web#153
Build: https://app.netlify.com/sites/roataway/deploys/61721171aa8d4d00086a89d2
Preview: https://deploy-preview-153--roataway.netlify.app/
Beta Was this translation helpful? Give feedback.
All reactions