Installations
npm install cra-template-orange
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
18.13.0
NPM Version
8.19.3
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (90.81%)
HTML (6.66%)
CSS (2.46%)
Shell (0.07%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
nipunadodan
Download Statistics
Total Downloads
761
Last Day
1
Last Week
2
Last Month
24
Last Year
116
GitHub Statistics
1 Stars
17 Commits
1 Forks
2 Watchers
2 Branches
1 Contributors
Updated on Jun 12, 2023
Bundle Size
1.26 kB
Minified
619.00 B
Minified + Gzipped
Package Meta Information
Latest Version
1.0.3
Package Id
cra-template-orange@1.0.3
Unpacked Size
61.79 kB
Size
35.45 kB
File Count
49
NPM Version
8.19.3
Node Version
18.13.0
Published on
Feb 09, 2023
Total Downloads
Cumulative downloads
Total Downloads
761
Last Day
0%
1
Compared to previous day
Last Week
-75%
2
Compared to previous week
Last Month
242.9%
24
Compared to previous month
Last Year
-63.9%
116
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads

No dependencies detected.
React.js Boilerplate with Tailwind and React Router DOM
This project is bootstrapped with Create React App - PWA addressing common needs such as,
- A routing library
- An .env handler for handling environment
- SASS and tailwind for styling
- Dark mode enabled if needed
- Pre-built commonly needed components
- Auth-restricted pages/components
- A well-formed file structure
- Ability to turn it to a PWA
and addressing common workarounds for well known issues like persistence over refreshes to minimise the setup time almost to none.
Setup
Use npx to create the React App
1npx create-react-app <project-path> --template cra-template-orange
Use the template locally
- Download or Clone the repository.
- Run,
1npx create-react-app <project-path> --template file:path/to/your/template/cra-template-orange
Edit the template or adding packages
- Template files can be found in
template
folder to add/edit/remove. - To add/edit/remove packages edit the
template.json
file.
Available features
There are several readily available libraries, components and functions out of the box. Default scripts are also changed as shown below. In addition, several ready-made components are available to use as is or to customise.
Added libraries through package.json
1{ 2 "dependencies" : { 3 "react-router-dom": "^6.3.0" 4 }, 5 "devDependencies": { 6 "autoprefixer": ">=10", 7 "dotenv-cli": ">=6", 8 "sass": ">=1", 9 "tailwindcss": ">=3" 10 }, 11 "scripts": { 12 "build:test": "dotenv -e .env.dev react-scripts build && rm -rf build-test && cp -r build build-test", 13 "build:prod": "dotenv -e .env.production react-scripts build", 14 "build": "echo \"Please use build:dev or build:prod \" && exit 1" 15 } 16}
Template Folder Structure
Featured files only,
1├── public 2│ ├── .htaccess # This solves the refreshing problem for routes (Described in a later section) 3│ └── index.html 4├── src 5│ ├── App.js # Acts as the router 6│ ├── components 7│ │ ├── common 8│ │ │ ├── index.js # Indexes the sibling components so it will be able to import all in one line) 9│ │ │ ├── Modal.js 10│ │ │ └── ThemeToggle.js 11│ │ ├── pages 12│ │ │ ├── home 13│ │ │ │ └── Home.js 14│ │ │ ├── index.js 15│ │ │ ├── login 16│ │ │ │ ├── LoginForm.js 17│ │ │ │ └── Login.js 18│ │ │ └── NotFound.js # The 404 file 19│ │ └── template 20│ │ │ ├── Footer.js 21│ │ │ ├── Header.js 22│ │ │ └── index.js 23│ ├── contexts 24│ │ ├── index.js 25│ │ ├── SiteSettingsContext.js 26│ │ └── ThemeContext.js 27│ ├── index.css 28│ ├── index.js # The main index file where the #root resides 29│ └── use-cases 30│ ├── cache 31│ │ └── get-cached-fetch.js 32│ ├── create-markup.js 33│ ├── index.js 34│ ├── is-logged-in.js 35│ ├── iso-local-date.js 36│ ├── private-route.js 37│ ├── relative-day.js 38│ └── use-auth.js 39└── tailwind.config.js
Usage
Enabling PWA
1// If you want your app to work offline and load faster, you can change 2// unregister() to register() below. Note this comes with some pitfalls. 3// Learn more about service workers: https://cra.link/PWA 4serviceWorkerRegistration.unregister();
As the comment states, switching serviceWorker.unregister()
to serviceWorker.register()
will opt you in to using the service worker.
You can totally remove Google Workbox libraries from the package.json
if you don't desire this functionality.
Ready to use components
The app.js
is working solely as a router. Apart from a several commonly used components in the Common
and Pages
folders under src
, there are some helpers provided to beat commonly rising issues with ReactJS.
Access restriction to pages
PrivateRoute.js
will provide a solution for authentication while routing. You will have to save authentication details somewhere convenient to you and retrieve them on useAuth()
instead of retrieving from localStorage
if you prefer. You can find it under Helpers.js
.
Dark Mode Switching
ThemeContext
is included to function as the dark mode switcher. You can use ThemeToggle
component to toggle the theme. Remember to add ThemeProvider
to App.js
and set darkMode: 'class'
in tailwind.config.js
Solving the refreshing problem with .htaccess
In order to make sure the App will be routed correctly when refreshed, an .htaccess is introduced to redirect the requests to index.html. This solution will only work with Apache servers. For other solutions read, this (StackOverflow) or this (React Docs).
1RewriteBase / 2RewriteRule ^index\.html$ - [L] 3RewriteCond %{REQUEST_FILENAME} !-f 4RewriteCond %{REQUEST_FILENAME} !-d 5RewriteRule . /index.html [L]
Learn More

No vulnerabilities found.

No security vulnerabilities found.