For many developers (of which I am a part), as soon as I met a repetable pattern, I have an irresistible urge to automate it.
Lately, I realized that was no expo template with ReScript up-to date that allow me to quickly start a sideproject or a POC. That's why I was interested in expo template creation.
Let's check out together the steps to realize the same template I made !
How it works
An Expo template is just an Expo app hosted on npm ! We just need to create a new Expo app with our criteria and publish our package !
Creation of our basic application
If it's not the case, you need to install expo-cli :
We can now create our application :
We will choose the blank
template for a minimal confguration.
Project configuration
It's important to configure correctly our package.json
in order to publish our template on npm.
You need to make sure of several things:
- Remove the filed
private: true
- Put an available package name
- Add a licence
- Fill the informations like the author, the description and some keywords
Now, let's setup ReScript.
ReScript Configuration
Let's install the essential package of a ReScript application. We need the React Native and React bindings.
Add to our package.json
some handy scripts :
The ReScript scripts will must run on another terminal instance (in addition to the expo server).
Then let's continue with the configuration file bsconfig.json
that every ReScript project has :
As I wrote in the bsconfig.json
file, the main source will be the folder src
that we need to create. To that, we can add our entry point, the App.res
file :
All that remains is to modify the App.js
file to expose our ReScript compiled code :
Clean and publication
Our template is ready ! But before publishing it, we need to create .npmignore
file so as not to publish useless elements in our template :
Finally, let's get to publishing ! If it's the first time you publish a module, you will have to login :
Then you'll be able to publish the project
And voila ! You can now use this template when you create a new expo application :