npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cra-template-orange

v1.0.3

Published

A Create React App Template with essential ready-to-code components and libraries.

Downloads

6

Readme

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

npx create-react-app <project-path> --template cra-template-orange

Use the template locally

  1. Download or Clone the repository.
  2. Run,
npx create-react-app <project-path> --template file:path/to/your/template/cra-template-orange

Edit the template or adding packages

  1. Template files can be found in template folder to add/edit/remove.
  2. 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

{
  "dependencies" : {
    "react-router-dom": "^6.3.0"
  },
  "devDependencies": {
    "autoprefixer": ">=10",
    "dotenv-cli": ">=6",
    "sass": ">=1",
    "tailwindcss": ">=3"
  },
  "scripts": {
    "build:test": "dotenv -e .env.dev react-scripts build && rm -rf build-test && cp -r build build-test",
    "build:prod": "dotenv -e .env.production react-scripts build",
    "build": "echo \"Please use build:dev or build:prod \" && exit 1"
  }
}

Template Folder Structure

Featured files only,

├── public
│     ├── .htaccess # This solves the refreshing problem for routes (Described in a later section)
│     └── index.html
├── src
│     ├── App.js # Acts as the router
│     ├── components
│     │     ├── common
│     │     │     ├── index.js  # Indexes the sibling components so it will be able to import all in one line)
│     │     │     ├── Modal.js
│     │     │     └── ThemeToggle.js
│     │     ├── pages
│     │     │     ├── home
│     │     │     │     └── Home.js
│     │     │     ├── index.js
│     │     │     ├── login
│     │     │     │     ├── LoginForm.js
│     │     │     │     └── Login.js
│     │     │     └── NotFound.js # The 404 file
│     │     └── template
│     │     │     ├── Footer.js
│     │     │     ├── Header.js
│     │     │     └── index.js
│     ├── contexts
│     │     ├── index.js
│     │     ├── SiteSettingsContext.js
│     │     └── ThemeContext.js
│     ├── index.css
│     ├── index.js # The main index file where the #root resides
│     └── use-cases
│           ├── cache
│           │     └── get-cached-fetch.js
│           ├── create-markup.js
│           ├── index.js
│           ├── is-logged-in.js
│           ├── iso-local-date.js
│           ├── private-route.js
│           ├── relative-day.js
│           └── use-auth.js
└── tailwind.config.js

Usage

Enabling PWA

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://cra.link/PWA
serviceWorkerRegistration.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).

RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

Learn More

Visit Create React App README.md or Docs to learn more.