Skip to content

A modified CRA template that uses Preact, with TailwindCSS. Use with Preact CLI.

License

Notifications You must be signed in to change notification settings

richardneililagan/cra-preact-tailwind-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cra-preact-tailwind-template

This is a modified Create React App (CRA) template for Preact CLI, that uses Preact (instead of React), and is already enabled for use with TailwindCSS.

Usage

# :: change {my-project} to your desired app / folder name
npx preact-cli create richardneililagan/cra-preact-tailwind-template my-project

Why?

I'm more accustomed to working with CRA, but have recently wanted to switch out React for Preact --- so this should allow you to use Preact while still being able to use the conventions + features + familiarities that CRA provides.


Notable customizations

customize-cra and react-app-rewired

This template uses customize-cra and react-app-rewired to hook up custom plugins in places to the default CRA pipeline.

Automatic pragma injection

The preact.h pragma is automatically injected into your JSX files, so you don't have to import { h } from 'preact' (or even import React from 'react') in your JSX files, nor do you have to add /** @jsx h **/.

This should also work in your tests (using jest by default).

Compatibility with React

Libraries that depend on React itself should be compatible with this out of the box. Any import calls for react and react-dom should be transparently aliased in webpack to their corresponding Preact compatibility libraries accordingly.

In tests, any imports for @testing-library/react are also aliased to @testing-library/preact.

TailwindCSS

TailwindCSS is already set up in the project, and TailwindCSS utility classes should work with your markup + components.

If you do still need to import custom CSS rulesets into your components, the original CRA behavior of being able to import .css and/or .module.css files into your code will still work.

To modify / extend the TailwindCSS configuration, check tailwind.config.js.

If you'd like to add additional global base styling to your app, src/index.css has a section dedicated to placing these rulesets in. This helps ensure that your global base rulesets are set within the right place in the CSS bundling pipeline.

Note that, to minimize CSS bundle sizes in production, TailwindCSS can purge unused CSS classes from your codebase. The template configuration will scan all .js/.jsx/.ts/.tsx files in src/, and all .html files in public/ to determine which CSS classes are actually in use.

For more information on this behavior, please read the TailwindCSS documentation.

ESlint configuration

You're more than welcome to switch out the ESlint config with your own preferences, and the template uses the following as default:

  • preact
  • unicorn
  • jest-dom
  • testing-library
  • prettier

See .eslintrc for more information.


@techlifemusic · website

About

A modified CRA template that uses Preact, with TailwindCSS. Use with Preact CLI.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published