Customizing default template
See original GitHub issueHey guys!
We would like to use all the power provided by create-react-app every time we start with a new project. As we always add few extra libraries after the app is created like react-router, redux, classnames and use a slightly different project structure to the provided by the default template, I was wondering if there is a recommended way of doing this repetitive work.
Here is what I tried so far:
-
Fork of
react-scripts
and modify the default template With this solution is possible to modify the generated app structure. However, adding new dependencies is not quite simple. It takes adding a.template.dependencies.json
and modifying thescripts/init.js
so it installs the additional dependencies if present even when a custom template is not provided via--internal-testing-template
and avoid installing react and react-dom when previously installed. I’m wondering if this could be a feature request itself.A downside I see with this approach is it takes maintaining your own version of react-scripts even when you don’t need to modify the react-scripts dependencies itself but the template’s dependencies.
-
CRAFT. React Create App From Template This is a very interesting concept. This command line utility allows you to use your own template when creating a new app. The problem is it doesn’t really create a new app but basically copies a repository with a previously created react app then applies some changes to the output, as far as I could see. This is far from being ideal since when I’m creating a new app, I would prefer using the most recent version of react-scripts as possible rather on rely on the one installed in the template, which may be outdated.
This may be an advanced use case and not sure if it is out of the core ideas for this awesome project but it seems create-react-app already contains most of the things needed to support something like this:
create-react-app MyApp --template <url-to-template>
Does anyone know what is the general recommendation from the community to deal with this case?
Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:9
- Comments:15 (4 by maintainers)
Top GitHub Comments
Hello everyone, I was digging the same issue as I’m creating a small fork (as suggested into the official docs) to support some webpack extensions (like in react-app-rewired) and adding some custom templates.
I found out that
--internal-testing-template
is currently supported and will try to fetch a template folder from thecwd
.It works decently enough for me, but I’ve tweaked a little bit the
init.js
so to be able to host more basic templates in my own version ofreact-scripts
.I hope this flag that seems so experimental will one day become just
--template
as you all suggest!https://github.com/facebook/create-react-app/issues/2960#issuecomment-356108258
This logic can be applied to CRA itself, right?
Lots of boilerplate generating CLI’s have a
--template
flag.They make the mistake of making those templates 3rd party, but if CRA team would maintain a few variants then
--template
could be handy.Very specifically: I hate having to delete all the junk in a CRA app (yes I fire up a lot of CRA apps just to test misc stacks) and would love a
--template=bare
or just--bare
flag. I really don’t care about the rest.