You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Actually, there is only one difference: Preact requires different @jsx pragma definition. I tried to build a Preact-based project with react-scripts and realized that we need to tell ESlint and Babel about new rules.
I think it’s great many projects can run on Preact without significant changes but I don’t think we’ll be spending effort supporting this as a built-in configuration (just like we don’t support, for example, Relay out of the box).
The best course of action for those interested in it would be to fork react-scripts (as described in #779), make the necessary changes, and try to keep it up to date with upstream version.
Well, forking may be a solution. I will try to create a fork and use it.
Actually, there already was an attempt to do this: https://github.com/alexkuz/create-preact-app
It seems like there were no pulls from upstream since forking, so I have to do this again.
@alexkuz, is there any chance that you will update your create-preact-app fork?
@just-boris I am working on putting this in my fork. Will get back to you when I am done. I need someone to test complete compatibility, as i don't have a lot experience with preact.
@just-boris I could, but tbh I'm not really using preact (at least for now), so I have no big interest to keep it up to date. Just fork it and update. Or I could transfer this fork to you if you want to take care of it from here.
@alexkuz that was not possible to pick up your fork, because the structure of main repo was changed a lot since that time (now this is a monorepo with Lerna).
But it would be helpful if you will put a note about my newer fork in your Readme.
Also, I have opened "Issues" section in my repo, any further suggestions are welcome
Reacted by Alexander Kuznetsov, Francisco Gileno de Oliveira Junior, Evgenii Khramkov, Adrien Antoine, Tyler, Prosper Otemuyiwa, Zak King, Sergey Makarov and Adam Faryna
This doesn't work in tests. It gives an error "Cannot find module 'react' from 'App.test.js'". Can't jest read aliases? Is there any way to configure jest to use preact for react?
It worked when I added to preact-compat to ModuleNameMapper in package.json. However, enzyme didn't work. It would be great if we have a full implementation with preact-compat from someone.
Activity
just-boris commentedon Dec 10, 2016
Actually, there is only one difference: Preact requires different
@jsx pragmadefinition. I tried to build a Preact-based project withreact-scriptsand realized that we need to tell ESlint and Babel about new rules.So I tried to add the following
babelrc:and
eslintrcThe only problem is that
react-scriptsignoreseslintrcandbabelrc, so my changes have no effect.gaearon commentedon Dec 10, 2016
I think it’s great many projects can run on Preact without significant changes but I don’t think we’ll be spending effort supporting this as a built-in configuration (just like we don’t support, for example, Relay out of the box).
The best course of action for those interested in it would be to fork
react-scripts(as described in #779), make the necessary changes, and try to keep it up to date with upstream version.just-boris commentedon Dec 10, 2016
Well, forking may be a solution. I will try to create a fork and use it.
Actually, there already was an attempt to do this: https://github.com/alexkuz/create-preact-app
It seems like there were no pulls from upstream since forking, so I have to do this again.
@alexkuz, is there any chance that you will update your create-preact-app fork?
shrynx commentedon Dec 11, 2016
@just-boris I am working on putting this in my fork. Will get back to you when I am done. I need someone to test complete compatibility, as i don't have a lot experience with preact.
alexkuz commentedon Dec 11, 2016
@just-boris I could, but tbh I'm not really using preact (at least for now), so I have no big interest to keep it up to date. Just fork it and update. Or I could transfer this fork to you if you want to take care of it from here.
gaearon commentedon Dec 11, 2016
Oh hi @alexkuz
just-boris commentedon Dec 17, 2016
Hello again,
So far, I have been working on this solution and have finally published my fork. So, if you want to create a Preact app without any setup, you may run
and it will give you a Preact-based application.
@alexkuz that was not possible to pick up your fork, because the structure of main repo was changed a lot since that time (now this is a monorepo with Lerna).
But it would be helpful if you will put a note about my newer fork in your Readme.
Also, I have opened "Issues" section in my repo, any further suggestions are welcome
just-boris commentedon Dec 17, 2016
For those, who wants to check out, what was changed, you may look at this diff
shrynx commentedon Dec 18, 2016
@just-boris For a complete react compatibility wouldn't one need preact-compat too ?
In my fork i alias react and react-dom to preact-compat
https://github.com/shrynx/react-super-scripts/blob/0c4c4ddbabc77847a9694647c28dd94e48251ec3/packages/react-scripts/utils/customWebpackConfig.js#L19-L28
just-boris commentedon Dec 18, 2016
Yes, just added this feature per request in just-boris#1.
just-boris commentedon Dec 18, 2016
Closing this as no any further action from the upstream side.
gaearon commentedon Dec 19, 2016
Nice, thank you for sharing this!
prasadmsvs commentedon Jan 23, 2018
This doesn't work in tests. It gives an error "Cannot find module 'react' from 'App.test.js'". Can't jest read aliases? Is there any way to configure jest to use preact for react?
gaearon commentedon Jan 23, 2018
Not without ejecting. (Just like you can’t configure any other alias.)
prasadmsvs commentedon Jan 25, 2018
It worked when I added to preact-compat to ModuleNameMapper in package.json. However, enzyme didn't work. It would be great if we have a full implementation with preact-compat from someone.
just-boris commentedon Jan 28, 2018
@prasadmsvs I am still maintaining my fork supporting Preact. In version 1.1.0 I have also added a mapping into Jest config.
Also, look at the official Preact documentation: https://preactjs.com/guide/unit-testing-with-enzyme
UPD: there is also Enzyme v3 adapter: https://github.com/aweary/preact-enzyme-adapter, but it is not published to NPM yet.