• Stars
    star
    608
  • Rank 73,735 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 4 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ”ฅ A schematic that adds Tailwind CSS to Angular applications

Angular Tailwind CSS Schematics

This schematic will add Tailwind CSS to your Angular application.

Angular Tailwind CSS Schematics

Versions

@ngneat/tailwind AngularCLI
v7.x.x >= 11.2.x
v6.x.x >= v11.1.x, < 11.2.x
v5.2.5 < v11.1.x

v7.x.x

In v7, we leverage the built-in TailwindCSS support from AngularCLI if you use AngularCLI >= 11.2. When you invoke the schematics, and you have AngularCLI <11.2 installed, you'll see the following message:

Detected AngularCLI version is 11.0.7 which does not support TailwindCSS natively.
Please run "ng add @ngneat/tailwind@6" for Custom Webpack support.

v6.x.x

The main difference is Angular CLI v11.1+ uses PostCSS 8 already, so we remove that from our dependencies list. To use these schematics at specific version, please use this syntax: ng add @ngneat/[email protected] or npm i -D @ngneat/[email protected]

Usage

ng add @ngneat/tailwind

Usage with Nx

IMPORTANT for AngularCLI users: As of April 06 2021, create-nx-workspace@latest still generates Angular with AngularCLI 11.0.7 which does not have built-in TailwindCSS support. Please update AngularCLI by running ng update @angular/cli before running this schematics.

In Nx, you can either use AngularCLI or NxCLI. If you set up your Nx Workspace to use AngularCLI, the usage is the same as above. If you set up your Nx Workspace with NxCLI, follow the steps:

Install @ngneat/tailwind first:

npm i -D @ngneat/tailwind tailwindcss postcss autoprefixer
yarn add -D @ngneat/tailwind tailwindcss postcss autoprefixer

then execute the schematics:

nx generate @ngneat/tailwind:nx-setup

Manual steps

v7.x.x

In v7, we do not use a Custom Webpack anymore. If you use Custom Webpack, please follow the below guide and use @ngneat/tailwind@6

v6.x.x

If your projects are already using a custom Webpack builder with a custom webpack.config, follow these steps to add TailwindCSS to your project

  • npm i -D @ngneat/tailwind tailwindcss (or yarn add -D @ngneat/tailwind tailwindcss)
  • Import addTailwindPlugin from @ngneat/tailwind in your webpack.config
  • Import your TailwindCSS config in your webpack.config
  • Before you return or modify the original Webpack config, call addTailwindPlugin with the following parameters:
    • webpackConfig: the Webpack config
    • tailwindConfig: the TailwindCSS config that you import
    • patchComponentsStyles?: this flag will enable using TailwindCSS directives in components' stylesheets. Default to false because turning it on might impact your build time
// example
const { addTailwindPlugin } = require('@ngneat/tailwind');
const tailwindConfig = require('relative/path/to/tailwind.config');

module.exports = (config) => {
  addTailwindPlugin({
    webpackConfig: config,
    tailwindConfig,
    patchComponentsStyles: true,
  });
  return config;
};

Angular Material

If you plan to use @ngneat/tailwind with @angular/material, please make sure that you setup @angular/material before @ngneat/tailwind because @angular/material:ng-add schematics will error out if it detects a custom Webpack in your angular.json.

Purge

@ngneat/tailwind uses built-in purge functionality by tailwindcss (under the hood, it is postcss-purgecss). By default, @ngneat/tailwind sets the content to any HTML and any TS files in the project.

This behavior can be modified as the consumers see fit.

Tailwind JIT (v7.x.x only)

In v7, @ngneat/tailwind provides an option to enable JIT mode for TailwindCSS. This is a new compilation mode that improves the compilation time as it does not compile ALL of TailwindCSS anymore but only compiles what you use in your application. This mode is still in preview as of [email protected]

CSS Preprocessors

If you're using CSS Preprocessors (SASS/SCSS, LESS, Stylus) in your application, please check out TailwindCSS's Using with Preprocessors guide

Contributing

  • Fork this repo and clone the fork on your machine.
  • Run npm install to install all the dependencies
  • Start working on changes

Structure

_apps
 |__tailwind-e2e (e2e tests)
_libs
 |__tailwind
    |__src
       |__schematics
          |__ng-add (AngularCLI schematics)
          |__nx-setup (NxCLI schematics)
          |__files (files template to be generated)
          |__specs (unit tests)
          |__schema.d.ts (interface)
       |__constants (constants used in the project)
       |__utils (utilities functions)
       |__collection.json (schematics configuration)
       |__package.json (package.json of @ngneat/tailwind which will be published to npm)

Commit

  • Run git add . to stage your changes
  • Run npm run commit to start Conventional Commit flow

Commit Hooks

pre-commit will execute npm run lint and pretty-quick to lint and reformat.pre-commit does not run Unit Tests because Unit Tests will be ran in Github Actions. Feel free to run the Unit Tests with npm run test to test your changes

E2E Tests

Please run npm run e2e to run E2E tests before pushing

Updating README

README is in two places at the moment: root and libs/tailwind/README.md. The one in root is the one displayed on Github while the one in libs/tailwind is being used on npm. When you make changes to README, make sure to update both.

A script can be created to automating this.

PR

When everything passes and looks good, make a PR. Thanks for your contribution.

Contributors โœจ

Thanks goes to these wonderful people (emoji key):


Chau Tran

๐Ÿ’ฌ ๐Ÿ’ป ๐Ÿ“– ๐Ÿค” ๐Ÿ‘€

Netanel Basal

๐Ÿ’ป ๐Ÿค”

Santosh Yadav

๐Ÿค” ๐Ÿง‘โ€๐Ÿซ

BK

๐Ÿ’ป ๐Ÿค”

beeman

๐Ÿค” ๐Ÿง‘โ€๐Ÿซ ๐Ÿ’ป

Vlad Tansky

๐Ÿ’ป

Abhinav Dinesh C

๐Ÿ’ป

Suguru Inatomi

๐Ÿ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

More Repositories

1

falso

All the Fake Data for All Your Real Needs ๐Ÿ™‚
TypeScript
3,098
star
2

spectator

๐ŸฆŠ ๐Ÿš€ A Powerful Tool to Simplify Your Angular Tests
TypeScript
2,068
star
3

transloco

๐Ÿš€ ๐Ÿ˜ The internationalization (i18n) library for Angular
TypeScript
1,856
star
4

until-destroy

๐ŸฆŠ RxJS operator that unsubscribe from observables on destroy
TypeScript
1,733
star
5

elf

๐Ÿง™โ€โ™€๏ธ A Reactive Store with Magical Powers
TypeScript
1,527
star
6

content-loader

โšช๏ธ SVG component to create placeholder loading, like Facebook cards loading.
TypeScript
733
star
7

hot-toast

๐Ÿž Smoking hot Notifications for Angular. Lightweight, customizable and beautiful by default.
TypeScript
687
star
8

cashew

๐Ÿฟ A flexible and straightforward library that caches HTTP requests in Angular
TypeScript
677
star
9

reactive-forms

(Angular Reactive) Forms with Benefits ๐Ÿ˜‰
TypeScript
609
star
10

query

๐Ÿš€ Powerful asynchronous state management, server-state utilities and data fetching for Angular Applications
TypeScript
555
star
11

forms-manager

๐Ÿฆ„ The Foundation for Proper Form Management in Angular
TypeScript
517
star
12

error-tailor

๐Ÿฆ„ Making sure your tailor-made error solution is seamless!
TypeScript
478
star
13

helipopper

๐Ÿš A Powerful Tooltip and Popover for Angular Applications
TypeScript
392
star
14

nx-serverless

๐Ÿš€ The Ultimate Monorepo Starter for Node.js Serverless Applications
TypeScript
388
star
15

dialog

๐Ÿ‘ป A simple to use, highly customizable, and powerful modal for Angular Applications
TypeScript
371
star
16

hotkeys

๐Ÿค– A declarative library for handling hotkeys in Angular applications
TypeScript
325
star
17

edit-in-place

A flexible and unopinionated edit in place library for Angular applications
TypeScript
252
star
18

svg-icon

๐Ÿ‘ป A lightweight library that makes it easier to use SVG icons in your Angular Application
TypeScript
251
star
19

inspector

๐Ÿ•ต๏ธ An angular library that lets you inspect and change Angular component properties
TypeScript
218
star
20

dirty-check-forms

๐ŸฌDetect Unsaved Changes in Angular Forms
TypeScript
199
star
21

input-mask

๐ŸŽญ @ngneat/input-mask is an angular library that creates an input mask
TypeScript
199
star
22

lib

๐Ÿค– Lets you focus on the stuff that matters
TypeScript
180
star
23

transloco-keys-manager

๐Ÿฆ„ The Key to a Better Translation Experience
TypeScript
174
star
24

dag

๐Ÿ  An Angular service for managing directed acyclic graphs
TypeScript
153
star
25

bind-query-params

Sync URL Query Params with Angular Form Controls
TypeScript
147
star
26

from-event

๐ŸฆŠ ViewChild and FromEvent โ€” a Match Made in Angular Heaven
TypeScript
137
star
27

overview

๐Ÿค– A collection of tools to make your Angular views more modular, scalable, and maintainable
TypeScript
118
star
28

aim

Angular Inline Module Schematics
TypeScript
97
star
29

cmdk

Fast, composable, unstyled command menu for Angular. Directly inspired from pacocoursey/cmdk
TypeScript
91
star
30

copy-to-clipboard

โœ‚๏ธ Modern copy to clipboard. No Flash.
TypeScript
78
star
31

variabless

JS & CSS - A Match Made in Heaven ๐Ÿ’Ž
HTML
78
star
32

loadoff

๐Ÿคฏ When it comes to loaders, take a load off your mind...
TypeScript
78
star
33

effects

๐Ÿช„ A framework-agnostic RxJS effects implementation
TypeScript
63
star
34

avvvatars

Beautifully crafted unique avatar placeholder for your next angular project.
TypeScript
46
star
35

react-rxjs

๐Ÿ”Œ "Plug and play" for Observables in React Apps!
TypeScript
37
star
36

subscribe

Subscription Handling Directive
TypeScript
34
star
37

elf-ng-router-store

Bindings to connect Angular router to Elf
TypeScript
24
star
38

ng-standalone-nx

TypeScript
24
star
39

lit-file-generator

๐ŸŽ A lit generator for a component, directive, and controller.
JavaScript
19
star
40

storage

TypeScript
18
star
41

material-schematics

TypeScript
3
star
42

svg-icon-demo

TypeScript
1
star