Git Product home page Git Product logo

ng-tailwindcss's Introduction

ng-tailwindcss

A CLI tool for integrating Tailwind CSS into Angular-CLI projects with as little pain as possible

Read this article to learn more about how and why this works. You can also use it with other frameworks like React and Next.js!

Core Features:

  • PurgeCSS v1.4.2, ready to rock "out of the box", but also fully configurable

  • Sass support with optional dependency on node-sass or dart-sass

  • Default configurations reflect Tailwind v1 file naming conventions (such as tailwind.config.js)

  • Angular Workspaces (and other monorepo structures) Support (ngtw v2.2.0+)

  • Watch related files using watchRelatedFiles property of ng-tailwind.js config. This array of paths/globs will be watched for changes and trigger rebuilding of tailwind files.

  • "Hot reloading" of all watched files, including ng-tailwind.js. Any file change or renaming or reconfiguring will automatically be picked up by ngtw, no need to kill or restart your dev server! ๐Ÿš€

Why Is This Necessary?

If you haven't used Tailwind CSS yet, you really should! However, if you are trying to use Tailwind in an Angular project, you will quickly realize that the best features of tailwind are found in the build process, which is conveniently automated using (mostly) postCSS plugins. Unfortunately, Angular currently does not offer developers access to the webpack configuration being used 'under the hood', so you're out of luck. Unless...

You use ng eject! (not available in v6+)

If you are ok with losing all of the benefits of angular-cli (not advisable given the improvements continually being made to it), you can reference this excellent SO answer or YouTube video and learn how to get at the postCSS controls. Using this method, you will certainly enjoy faster development speed when dealing with styles. But when you reach for ng generate, ng add, or ng upgrade etc., you may find that you'll have some regrets, because running ng eject is PERMANENT. I hope you enjoy creating components 'by hand.'

However, if you're into having cake and eating it too, ng-tailwindcss is what you've been looking for! With a few straightforward CLI commands, you can retain the development advantage of angular-cli and enjoy all the benefits of the best CSS utility framework on the web. Oh, and did we mention PurgeCSS???

Let's get down to business:

Quick and Dirty Setup

(Recommended for new projects only, see Configuration section for safe handling of existing projects)

After starting your new angular-cli project run these commands:

npm i ng-tailwindcss -g
npm i tailwindcss -D
npx tailwind init # use --full, if you want to see all the defaults in your tailwind.config.js
ngtw configure
touch src/tailwind.css

Put all your tailwind imports in src/tailwind.css and run:

ngtw scripts

Run npm start and let the wind fill your wings!


Full Installation and Usage Guide

  1. Install globally: npm i ng-tailwindcss -g

  2. If you don't already have an angular project up and running, start your angular project (assumes angular cli is already installed globally): ng new angular-meets-tailwind

  3. Follow Steps 1-3 from the Tailwind Installation Instructions:

    A recommendation for new projects (no changes to global stylesheet yet) is to touch src/tailwind.css and use that file for all global styles and component classes. See Configuration section for existing projects.

  4. Configure your tailwind source/destination/config files by running:

    ngtw configure --config ./path/to/whatever-you-named-tailwind-config.js --source ./path/to/your-tailwind-source.css --output ./path/to/outputted-global-styles.css

    This will result in an ng-tailwind.js file at your project's root:

    module.exports = {
      // Tailwind Paths
      configJS: '/Absolute/path/to/whatever-you-named-tailwind-config.js',
      sourceCSS: '/Absolute/path/to/your-tailwind-source.css',
      outputCSS: '/Absolute/path/to/outputted-global-styles.css',
      watchRelatedFiles: [],
      // Sass
      sass: false,
      // PurgeCSS Settings
      ...
    }

    Please note that as of version 1.0.3, these paths will be absolute when created using the cli tool, though they can be manually edited to be relative paths with no adverse consequences.

    For those curious, under the hood, these properties correspond to the paths used in the tailwind build command like so:

    ./node_modules/.bin/tailwind build {sourceCSS} -c {configJS} -o {outputCSS}
    # npx is not assumed by this project, to avoid worrying about it as a dependency

    See Configuration section for more details and implications for existing Angular projects

  5. Add or adjust these scripts in your package.json:

    scripts: {
      "prestart": "ngtw build",
      "start": "ng serve & ngtw watch",
      "build": "ngtw build && ng build"
    }

    or simply run ngtw scripts to have these adjustments made automatically in your package.json.

    Now using npm start for your development server will ensure your tailwind files are being watched and built with your project, and you can still rely on the angular-cli for everything else (no ng eject! yay!).

  6. When you're ready to filter out your unused CSS, reference the documentation below for the various ways you can implement and adjust PurgeCSS. (Quick Tip: To include PurgeCSS in your build script, simply adjust the ngtw build command like so: ngtw build --purge.)

  7. Keep calm and angular on.


Configuration

The ng-tailwind.js file can be directly manipulated (in keeping with the tailwind way of doing things) after the initial configuration command has been run. Conversely, if you prefer the command line, running ngtw configure a second time will overwrite only the properties specified by the flags you include (e.g. ngtw configure -c ./new-tailwind-config.js will only change the configJS property, and retain the original values for sourceCSS and outputCSS).

Important: The default config (running ngtw configure with no arguments) will assume a configuration of:

{
  // Tailwind Paths
  configJS: './tailwind.config.js',
  sourceCSS: './src/tailwind.css',
  outputCSS: './src/styles.css',
  watchRelatedFiles: [],
  // Sass
  sass: false,
  // PurgeCSS Settings
  ...
}

Also important: these paths will actually be coerced to absolute paths. If you find this confusing, please open an issue, so the docs can be as clear as necessary.

It should be noted that such a configuration will set up your project to overwrite angular's default styles.css during each build, so if you desire to use the defaults in your existing project (recommended), you should remove any css from this file and place it in sourceCSS (the default being src/tailwind.css). If you are using styles.css as a source file (not really recommended), don't forget to edit your angular.json styles array to reflect your new global stylesheet (probably your outputCSS, but more complicated scenarios are certainly possible--be safe out there!).

Resetting to defaults

The --default flag can be included with the configure command at any time to overwrite all Tailwind Paths to the defaults (see below; PurgeCSS Settings will not change), with the exception of any other included flags when the command is run.

Example:

ng-tailwind.js (changed the file structure, needs an update)

module.exports = {
  // Tailwind Paths
  configJS: './some-tailwind-config.js',
  sourceCSS: './random/path/you/chose/tailwind.css',
  outputCSS: './way/different/location/of/styles.css'
  watchRelatedFiles: [],
  // Sass
  sass: false,
  // PurgeCSS Settings
  ...
}

bash script (this should fix it):

ngtw configure --default -o ./src/my-groovy-styles.css

ng-tailwind.js (updated)

module.exports = {
  // Tailwind Paths
  configJS: './tailwind.config.js', // default config value
  sourceCSS: './src/tailwind.css', // default source value
  outputCSS: './src/my-groovy-styles.css' // -o (--output) overrides default
  watchRelatedFiles: [],
  // Sass
  sass: false,
  // PurgeCSS Settings
  ...
}

PurgeCSS Implementation Guide

How it Works

It is important to note that PurgeCSS will manipulate the output CSS file itself, directly.

For example:

  • ngtw build produces =>
  • styles.css file of ~300kb (all possible selectors; results may vary) =>
  • ngtw purge takes in that stylesheet and =>
  • rewrites styles.css file of 6kb (same file location, but with only a fraction of the original selectors, and no comments)

"Ah, but how does PurgeCSS know what selectors I'm using?" you ask.

ng-tailwindcss uses a custom extractor that is run against all .html and .ts files in the /src directory. You can edit your PurgeCSS configuration in the ng-tailwind.js file. Read the PurgeCSS Docs to see what is possible and how to maximize the configuration for your project.

How To Use It

When including PurgeCSS in your Angular/Tailwind magnum opus, there are 3 ways to execute the script:

  1. Lock It in at the Configuration Level

    This strategy ensures that PurgeCSS will clean up your Tailwind-generated global stylesheet every time Tailwind builds.

    Usage: ngtw configure --purge

    This configure flag sets {purge: true} in your ng-tailwind.js file. This property defaults to false, but, when true, it will not be overridden by any other CLI commands that initiate a build. **It is important to note that any PurgeCSS configuration options set to true in the ng-tailwind.js file will not be overridden by a CLI command.

    However, you can set {purge: false} at any time by manually editing the file (of course), or running ngtw c --unset-purge.

    Example: PurgeCSS All The Things

    ngtw configure --default --purge
    ngtw scripts
    
    # Even though the scripts command does not create any PurgeCSS scripts,
    # the configuration of {purge: true} in ng- will cause PurgeCSS
    # to run after every successful Tailwind build.
  2. Run It with the ngtw Build Command

    This is a slightly more manual approach, where you are telling PurgeCSS to run with a flag on the build command.

    Usage: ngtw build --purge.

    Obviously, this tells tailwind to rebuild your stylesheet, then PurgeCSS is immediately excecuted on the resulting output file (outputCSS in ng-tailwind.js) using the settings specified in ng-tailwind.js.

    Example: Production Build Script

    "scripts": {
      "b-dev": "ngtw build && ng build", // dont purge
      "b-prod": "ngtw build --purge && ng build -c production" // purge
    }
  3. Run the Command Directly

    This gives you granular control over when PurgeCSS runs, as well as a few other options that can be altered with each execution.

    Usage: ngtw purge [--keyframes] [--fontface] [--rejected]

    At any time this command can be run to purge your outputCSS file. By default, the settings specified in your ng-tailwind.js file will be used, but any boolean properties (keyframes, fontface, rejected) that are false can be overridden to be true during this run with the use of the flags.

    Example: Debugging Dynamically Generated Selectors

    ngtw build && ngtw purge --rejected

    {project root}/rejectedCSS.json:

    [
      ".dynamically-generated-class", // Ah! Forgot to whitelist this one!
      ".useless-class",
      "#useless-id",
      "etc..."
    ]

    ng-tailwind.js:

    module.exports = {
      // Tailwind Paths
      configJS: './tailwind.config.js',
      sourceCSS: './src/tailwind.css',
      outputCSS: './src/styles.css',
      watchRelatedFiles: [],
      // Sass
      sass: false,
      // PurgeCSS Settings
      purge: false,
      keyframes: false,
      fontFace: false,
      rejected: false,
      whitelist: ['dynamically-generated-class'], // Problem solved
      whitelistPatterns: [/dynamically/, /generated/, /class/], // overkill, but also works
      whitelistPatternsChildren: [],
      extensions: ['.ts', '.html', '.js'],
      content: []
    }

Monorepo Support

If you are working with a monorepo structure where the content you need PurgeCSS to examine is not necessarily in the ./src/ directory, you can use the content property to define the path to those directories.

Example:

content: ['./app1/**/*.html', './app1/**/*.ts', '../app2/**/*.js']

The default extractor and default content glob/path (to the ./src/ directory) cannot be changed

If you have sub-projects that require fine-tuning of your ng-tailwind.js options, then you can create alternate ng-tailwind.js files for those sub-projects and leverage them in your watch/build/purge commands with the option --config (-c). For example, your package.json scripts might look like this:

{
  "start": "ng serve & ngtw watch", // serves up "main app" using the default ./ng-tailwind.js for configuration
  "start:other": "ng serve other & ngtw watch -c projects/other-app/other-ng-tailwind.js", // serves up sub-project in same monorepo with custom config file
  "build": "ngtw build && ng build",
  "build:other": "ngtw build other -c projects/other-app/other-ng-tailwind.js && ng build"
}

Using Sass

To take advantage of Sass in your tailwind.(s)css file, either node-sass or sass (dart-sass on Angular 8) must be installed in your project (most likely included with your Angular app unless you removed it somehow, because you have way too much time on your hands). In the rare scenario it is not installed, run npm i -O node-sass (or sass) in your project root (installs as optional dependency) and you're good to go.

Once this optional dependency is in place, configure for Sass with ngtw c --sass.

If for some reason your dependency tree contains node-sass and dart-sass and you prefer that dart-sass be used to compile your sass, you can edit the ng-tailwind.js file like so:

module.exports = {
  // Tailwind Paths
  ...
  // Sass
  sass: 'sass', // possible values: true, false, 'node-sass', 'dart-sass', and 'sass'. ('sass' == 'dart-sass')
  // PurgeCSS Settings
  ...
}

That's all! Keep in mind, this tool does not compile CSS/SCSS from any other files, so you'll still have to configure your angular.json for the rest, which is the preferred way to handle those files.

A note on how this is implemented: The compiled CSS from your tailwind.scss is stored in a temporary .css file that is immediately destroyed once the build is complete. At the moment, there is no way to alter this behavior. If this is not optimal for your situation, please file an issue.


Upgrading from older versions of ng-tailwindcss

The only breaking change ever introduced would be the name change of the default tailwind config file (tailwind.js => tailwind.config.js), otherwise all commands will continue to work as expected. However, newer versions do contain more features in the configuration file, which you may or may not be aware of or even want to make use of.

To take full advantage of the latest PurgeCSS or Sass capabilities, simply install the latest version globally with npm i -g ng-tailwindcss@latest, then run ngtw c and your ng-tailwind.js file will automatically fill out with the default PurgeCSS settings properties (of course, you could manually add them too, if you're into that sort of thing). Even without updating ng-tailwind.js, running any variety of the purge command will still work (default PurgeCSS Settings will be used).


A Few Notes About Existing Angular Projects

For existing projects that already have global stylesheets and other established CSS patterns, here are a few things to keep in mind:

  • On each build, Tailwind will overwrite the outputCSS file, so be sure to only edit the sourceCSS file with your custom styles.

  • Don't forget to adjust your angular.json styles array to reflect the outputCSS file, if you are using your original global stylesheet as your sourceCSS file.

  • If you already have complicated start/build/production/etc scripts, then manually customizing these scripts should be preferred over running ngtw s.

    • ngtw build should be included before any build process using && to ensure all stylesheets are up-to-date before the angular build takes place.

      ex: "build-prod": "ngtw build && ng build --prod --aot"

    • ngtw watch should be coupled with the dev server command (ng serve) using a single & so the processes run concurrently and can be killed concurrently.

      ex: "start": "ng serve & ngtw watch"

    • ngtw build should also be included in a prestart script to ensure that styles are up-to-date before launching the dev server. If your dev server starts with a different command (with no pre option), consider:

      ex: "custom dev command": "ngtw build && fancy -dev -server -command & ngtw watch

Running into a scenario not covered in this documentation? Open an issue!


Command Aliases

You can alias your commands or argument flags thus:

ng-tailwindcss => ngtw

    configure => c
        --config => -c
        --source => -s
        --output => -o
        --default => -d
        --purge => -p
        --unset-purge (no alias)
        --sass (no alias, and must be manually set to false)

    build => b
        --purge => -p
        --config => -c
    
    purge => p
        --keyframes => -k
        --fontface => -f
        --rejected => -r
        --config => -c

    watch => w
        --config => -c
    scripts => s

    --help => -h

including --help will provide a description of any command or argument.


Contributing

If you enjoy helping other developers get stuff done more efficiently, then we share a common goal, my friend. I would love to hear your ideas to make this project better, or to review your pull requests.

ng-tailwindcss's People

Contributors

antonellopasella avatar benjaminsteward avatar dependabot-preview[bot] avatar dependabot[bot] avatar euxn23 avatar sebasg22 avatar tehpsalmist avatar vcodx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ng-tailwindcss's Issues

React-compatible scripts

Create-react-app shares same basic folder structure, but (obviously), has different scripts and default global stylesheet name (index.css). Some tweaking, and this tool could be useful for React projects out of the box, as well. Currently, I'm thinking a --react (-r) flag would alter defaults and scripts accordingly, but maybe it would be a better user experience if the library intelligently detected what type of project it was (maybe add a framework property to the ng-tailwind.js file with string values like 'angular' and 'react'), so the user didn't have to worry about accidentally screwing up files if they forget the extra flag.

Overwrite built-in extractor

Currently it is not possible to overwrite the built in extractor.

module.exports = {
  extensions: [
    '.html'
  ],
  extractors: [{
    extractor: class {
      static extract (content) {
        console.info('Custom extractor');
        return [];
      }
    },
    extensions: ['.html']
  }]
}

Class missing after ngtw build --purge when using ngClass.

I am not entirely sure about this, but I noticed that when I used ngClass in a component to dynamically add the "hidden" class, it was not included in the final build after using --purge. Have you experienced this? Or am I doing something wrong?

<nav class="flex flex-col lg:flex lg:flex-row lg:items-center justify-between px-4 mt-4" [ngClass]="{ hidden: !isOpen }"> <!-- some stuff here --> </nav>

In the end I added an empty div with the hidden class just to make sure it was rendered.

ngtw watch issues and other minor improvements

Having some problems after following the installation instructions on a brand new Angular 8 application and a fresh install of ng-tailwindcss.

Starting with the minor stuff:

  1. The ng-tailwind.js file generated paths with '', which caused issues when I changed the path to 'src\sass\tailwind.scss' because '\s' was treated like an escaped character. Had to manually switch them to '/'.

  2. Sass documentation example shows to leave the files as .css in the config paths, but should probably be .scss instead. (Angular app is likely setup as scss if we're using it in tailwind)

  3. ngtw watch provides no output to the console saying the watch has started. Something like "Watching '@file' for changes..." would probably go a long way to avoid any confusion.

  4. ngtw -version would be nice so when we submit issues we can know what version we're on.

And now the larger issue:

  1. ngtw watch seems to only work once. A simple example:
@tailwind base;

@tailwind components;

@tailwind utilities;

.btn {
    @apply bg-blue-500 text-black font-bold py-2 px-4 rounded;
}

If I change 'text-black' to 'text-white', it compiles and works. If I undo and save the file, nothing happens. Making any changes to the file a second time doesn't trigger the watch.

require() is not a function error

When I add a plugin for Tailwind with a project with default ng-tailwind configuration I receive this error when I build.
I have the latest version of ng-tailwindcss, tailwindcss and angular.

Sass Compiled.
{ Error: Command failed: node_modules.bin\tailwind build "temporary-tailwind-css-file.css" -c "tailwind.config.js" -o "./src/styles.scss"
๏ฟฝ TypeError: require(...) is not a function
at Object. (tailwind.config.js:21
:36)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at tailwindcss\lib\index.js:74:
107
at processTailwindFeatures.js:34:20

at ChildProcess.exithandler (child_process.js:294:12)
at ChildProcess.emit (events.js:198:13)
at maybeClose (internal/child_process.js:982:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
killed: false,
code: 1,
signal: null,
cmd: 'node_modules\.bin\tailwind build "temporary-tailwind-css-file.css" -c "tailwind.config.js" -o > "./src/styles.scss"' }

Tailwind css output not being updated

I've started to have issues whereby any changes to tailwind.js is simply not being reflected elsewhere.
This was working fine up until this morning.

I'm now getting:

{ Error: Command failed: /Volumes/Work/MH/AngularTailwind/node_modules/.bin/tailwind build /Volumes/Work/MH/AngularTailwind/src/styles/tailwind/tailwind-source.css -c /Volumes/Work/MH/AngularTailwind/tailwind.js -o /Volumes/Work/MH/AngularTailwind/src/styles/tailwind/tailwind-output.css
/bin/sh: /Volumes/Work/MH: No such file or directory

I had a base project where everything was working. I copied and pasted that to have a foundation to work from. Now both are completely messed up. I've installed tailwind and ng-tailwindcss with absolutely no luck.

The only thing I can think of now is to create an entirely new project from scratch.

Purge appears to exclude classes following an id

During the development process, purge was set to false. Upon building for deployment, I set this to true but noticed that a bunch of custom styles in the config file were completely excluded.

After a little fiddling around, it appears to be that any custom styles that have an id element followed by a class seem to be excluded. For example:

#override_material_date .mat-form-field-underline { 
    @apply hidden !important;
}

However, if I were to remove the . from .mat-form-field-underline, then it compiles. What's also interesting is that in Visual Code, i have a find input open where I've typed in #override_material_date .mat-form-field-underline to check whether it was compiled into the output. When running npm run prestart, the keyword appears for about a second before being completely removed. Something in the process is removing it after it's been added.

Any help would be greatly appreciated.


Update
I turned the rejected property to true and have found a bunch of custom styles have been rejected. The result leads me to believe my original assumption might be incorrect.

  ".form-input",
  "#override_material_date .mat-form-field-wrapper",
  "#override_material_date .mat-form-field-label",
  "#override_material_date .mat-form-field-infix",
  "#override_material_date .mat-input-element",
  "#override_material_date .mat-input-element:focus",
  "#override_material_date .mat-form-field-suffix",
  ".annotate-options-wrapper",
  ".annotate-option",

When taking one of the classes above (.form-input), this class was originally presented in the config file as

.form-input, .search-input { }

Even after breaking these two out into their own lines with the exact same options, .form-input is still excluded.

.search-input {
    @apply text-sm pl-10 pr-4 py-3 block rounded mb-6 leading-tight w-full bg-gray-200 text-gray-600 border border-solid border-transparent;
}
.form-input {
    @apply text-sm pl-10 pr-4 py-3 block rounded mb-6 leading-tight w-full bg-gray-200 text-gray-600 border border-solid border-transparent;
}

As for the other rejected elements, I have no idea yet.

Tailwind css classes not working in angular 8

I've followed the instructions for installing into a new project, and I'm attempting to use the classes on my elements, but it appears they are not working. You can see the repo here, and here is an example of what I'm doing:

<div class="block text-gray-700">
  <div class="flex flex-row flex-no-wrap justify-around">
    <div class="unit">Daemon Prince of Nurgle</div>
    <div class="pl">9PL</div>
    <div class="pts">180pts</div>
  </div>
</div>

When I inspect the code, the system simply doesn't recognize any of the classes as existing at all--there is nothing in the list of styles in inspector.

Paths on Windows

hey, great lib!

But i have problems on windows system with the build process. Windows does not like ./ paths. Can you maybe fix this? :)

If not, I can build my own lib for windows :)

Thank you!

Tailwind per angular component

Hey,

quite often we have a dedicated styles per component:

@Component({
  selector: 'ui-modal',
  templateUrl: './modal.component.html',
  styleUrls: ['./modal.component.scss']
})
export class ModalComponent implements OnInit, OnDestroy {
//...
}

The main reason is to keep the styling close to component, also to lazy load it by angular.

Would be nice to have component styles under context of tailwind.

As we checked, we could @import url() each component stylesheet from sourceCSS file, but its error prone and still no lazy loading.

wrong paths in ng-tailwind.js

In my build process (github to firebase) the file 'src\tailwind.css' could not be found.
I had to change the paths in the file ng-tailwind.js:

sourceCSS: 'src\\tailwind.css',
outputCSS: 'src\\styles.css',

to:

sourceCSS: 'src\/tailwind.css',
outputCSS: 'src\/styles.css',

Sass issue

Hi.
I'm developing in angular 8 and have my styles set to .sass.

I set(in ng-tailwind.js) te sass: true but when I execute the ouput file results as .css. Is that correct? Doesn't it have to convert all to sass?

Clarification of Sass use in documentation

Hi, in the documentation regarding Sass it says:

To take advantage of Sass in your tailwind.(s)css file, node-sass must be installed in your project (most likely included with your Angular app unless you removed it somehow, because you have way too much time on your hands). In the rare scenario it is not installed, run npm i -O node-sass in your project root (installs as optional dependency) and you're good to go.

I created a new Angular 8 project with SCSS styling:

ng new tailwind-test --routing --style=scss

when setting sass to true in ng-tailwind.js ngtw warns that 'node-sass' is not installed.

I haven't explicitly removed node-sass, and my component-level scss is working, but its not listed as a dependency either in a new angular 8 project (I'm assuming its bundled up in ng cli?).

If I want to use SCSS/SASS Is it always necessary to install node-sass as an optional dependency? If it can't use whatever ng cli is using I think the documentation should reflect that.

Finally, thanks for this project! I'm excited about using tailwind and you have made it very easy to integrate it into angular.

ng-tailwindcss is useful with Next.js. So would you consider other name means even useful in even non-angular project?

I use ng-tailwindcss in Next.js project, and it seems to be works with no problem. (at here https://github.com/euxn23/next-ng-tailwindcss)
But ng-tailwindcss seems to be library for only Angular. (or programmer who don't know Angular context, ng naming may misleading... ๐Ÿ˜ญ )

Initialy, this library may be helper for only Angular, but now, this solution is beneficial for non-angular project (such as Next.js, Nuxt.js, even create-react-app project).

I think this solution should be known more widely known, and renaming may be effective.
How do you think?

Auto-rebuild

npm start builds Tailwind and then runs ng serve. Great!

However... Tailwind is not rebuilt and purgecss is not re-run when a file is updated.

The live dev server reloads the page.

There are missing styles.

I have to restart the server with ^C-up-enter...

Is there any better solution, for example auto rebuild?

Config option to specify path to ".html" files for purging css

First thing first, thank you for ng-tailwind. You did a great work with this package. I really appreciate your hard work and making Tailwind easily available for the people working in Angular.

I was wandering if you could add an extra config option (if this is already possible, please let me know) for people having their component templates in other folders than the default path which Angular generates (src at root level with the angular.json file).

In my case, our whole Angular application is under a frontend folder in a monorepo for the whole application.

So yeah, in order to achieve the purging effects, I had to point the purge.js script to the specific folder.

Not sure how common my use-case is, but it wouldn't hurt to be able to point to a specific folder for the purge functionality to scan for css classes used in templates.

Tailwind 2.0 Compatibility

Hi Team,

I've just installed Tailwind 2.0 > npm prestart =

> ngtw build

{ Error: Command failed: node_modules/.bin/tailwind build "./src/styles/tailwind/config.css" -c "./tailwind.config.js" -o "./src/styles/tailwind/output.css"
   ๐Ÿšซ Error: [object Object] is not a PostCSS plugin
    at Processor.normalize (/mypath/myproject/node_modules/postcss/lib/processor.js:168:15)
    at new Processor (/mypath/myproject/node_modules/postcss/lib/processor.js:52:25)
    at postcss (/mypath/myproject/node_modules/postcss/lib/postcss.js:55:10)
    at _lodash.default.flatMap.style (/mypath/myproject/node_modules/tailwindcss/lib/util/parseObjectStyles.js:24:33)
    at arrayMap (/mypath/myproject/node_modules/lodash/lodash.js:639:23)
    at map (/mypath/myproject/node_modules/lodash/lodash.js:9580:14)
    at Function.flatMap (/mypath/myproject/node_modules/lodash/lodash.js:9283:26)
    at parseObjectStyles (/mypath/myproject/node_modules/tailwindcss/lib/util/parseObjectStyles.js:23:26)
    at parseObjectStyles (/mypath/myproject/node_modules/tailwindcss/lib/util/parseObjectStyles.js:20:12)
    at _lodash.default.flatMap.style (/mypath/myproject/node_modules/tailwindcss/lib/util/processPlugins.js:37:123)

    at ChildProcess.exithandler (child_process.js:294:12)
    at ChildProcess.emit (events.js:198:13)
    at maybeClose (internal/child_process.js:982:16)
    at Socket.stream.socket.on (internal/child_process.js:389:11)
    at Socket.emit (events.js:198:13)
    at Pipe._handle.close (net.js:606:12)
  killed: false,
  code: 1,
  signal: null,
  cmd:

After following the guides here: https://tailwindcss.com/docs/upgrading-to-v2#upgrade-to-node-js-12-13-or-higher and here: https://tailwindcss.com/docs/installation#post-css-7-compatibility-build

npm install tailwindcss@latest postcss@latest autoprefixer@latest

npm install tailwindcss@npm:@tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9

I now get the following error when running the ng-tailwindcss command "prestart": "ngtw build",

{ Error: Command failed: node_modules/.bin/tailwind build "./src/styles/tailwind/config.css" -c "./tailwind.config.js" -o "./src/styles/tailwind/output.css"
/bin/sh: node_modules/.bin/tailwind: No such file or directory

    at ChildProcess.exithandler (child_process.js:294:12)
    at ChildProcess.emit (events.js:198:13)
    at maybeClose (internal/child_process.js:982:16)
    at Socket.stream.socket.on (internal/child_process.js:389:11)
    at Socket.emit (events.js:198:13)
    at Pipe._handle.close (net.js:606:12)
  killed: false,
  code: 127,
  signal: null,
  cmd:
   'node_modules/.bin/tailwind build "./src/styles/tailwind/config.css" -c "./tailwind.config.js" -o "./src/styles/tailwind/output.css"' }

Question: Watching Scss files

Is it possible setup ngtw to watch for changes in all files that are being imported into the main .scss file that ngtw watches?

Let's say i want to split the main .scss file into multiple files to contain components like buttons etc. Currently the watch is only triggered when changes are made to the "main.scss" file.

Importing custom css files to sourceCSS.

I am trying to import custom css files into sourceCSS. These custom css files contain tailwind syntax like @apply. While building the imports are just converted to the same imports in the outputCSS file.
My sourceCSS file looks like this

@import "tailwindcss/base";
@import "tailwindcss/components";

// Custom CSS Files
@import "./custom-css/auth.css";

@import "tailwindcss/utilities";

My custom css file auth.css looks like this

.auth-card{
  @apply border-2 shadow-lg p-3;
}

In my output file I got this

...
...
@import "./custom-css/auth.css";
..
..

The contents of auth.css is not getting processed by Tailwind.

Whereas if I directly add the content of auth.css to sourceCSS file then its getting built fine. This ofcourse is not what I want since I will be left with a very long sourceCSS file in the long run.


@import "tailwindcss/base";
@import "tailwindcss/components";

// This works
.auth-card{
  @apply border-2 shadow-lg p-3;
}

@import "tailwindcss/utilities";

Deprecation?

So, apparently with the advent of Angular 8, you can now extend the webpack configuration and get tailwind to work seamlessly with Angular, including using tailwind directives in component files.

It's possible that there may yet be uses for this package, so I'll happily update it if the need arises, but it also sounds like it has served its purpose and has now outlived its usefulness. Big thanks to the Angular team for making a great cli tool and continually rolling out developer-friendly updates! :)

For a guide on how to do Angular + Tailwind "the right way," check out this blog post.

NGTW build on save via Angular CLI?

Hi

I'm having pretty much easy question, but one of the most important for me right now. I'm making an app with the latest TailwindCSS and ng-tailwind version. Is there any way to call ngtw build on save (similarly like the Angular's CLI compiles). I am asking because now everytime i want to extract component, i need to call ngtw build command and in long term run it's a bit annoying. Can i fix that? I've heard that with ng eject we can access webpack and then do that there, but unfortunately there is no ng eject now (it's disabled).

Every feedback will be helpful and apprecieated!

Output stderror stream from tailwind command

err => {

I had an issue that error was not reported by exec command, but instead i got error printed inside stderror variable (something regarding wrong classes).

Suggestion, if stderror * 3 in exec callback) is not empty, print it to console.error (we could also call Promise.reject in case of an error, but this might cause some backward compatibility issues)

P.s. node 14.18.1,
"ng-tailwindcss": "2.2.0", (even with 2.3)
"tailwindcss": "^2.2.19",

JIT compilation?

Does this work with the new JIT compilation. It seems like a much better workflow and purge wouldn't be needed.

Thanks,

Slow compiling times

Hi

I'm making a fullstack Angular application (but separated frontend and backend stuff from each other). I'm having a problem with performance. When i'm reloading project, i'm getting very slow reloading time (~1 min). I am using the latest Angular version with latest ng-tailwindcss version. Am i doing something wrong or it's just an error?

I'll be thankful to every feedback :)

image
image

Avoid to install ng-tailwindcss globally

Is there a way to execute ngtw scripts without having ng-tailwindcss installed globally?

I tried with devDependencies and manage scripts but it's not working

Thanks!

Ability for Purge to include .LESS files in components

In my Angular project I may extract some components into the related .LESS file and import the tailwind.css output to utilise the classes. Additionally, for all things such as buttons, overlays, inputs I have additional independent .LESS files. I've found that when purging on build all LESS files are ignored and the app cannot build correctly.

Would it be possible for purge to include the .LESS extension?

Hot Reloading of ng-tailwind.js on file change

Up til now (with the pending release of 1.1.0 and PurgeCSS integration), this config file hasn't been a big deal (most likely) for typical users, but now that we will have PurgeCSS configurations stored here, and especially the whitelists, it is going to be a pain to update that and then have to refresh the dev server (think cmd+c -> npm start). I'm thinking that 1.1.1 or 1.1.2 should have some sort of smoothly implemented "hot-swapping" for that file, so the development workflow isn't interrupted when a selector is added to the whitelist (for example).

Here's how I see the feature working:

  1. The ng-tailwind.js file is watched in some fashion
  2. When the file changes, the hot-swapping takes place so that the ng-tailwindcss modules relying on it now 're-require' it and thus have the updated version of the object.
  3. With the updated version now in place, probably run the build/purge scripts, but this might need some fine-tuning so the dev still has a choice of running purge or not, but also doesn't have to worry about doing anything extra when he/she edits the ng-tailwind.js file.

gitignore for output file

I think one thing missing in the documentation is guidance that the output file should probably be gitignored.

<3 this project, and thanks for the great docs!

Update to be fully Tailwind 1.0.0 compatible

Not a ton to do here, but definitely would need to change some default file names, like tailwind.config.js, for example.

Obviously I will wait to release any of these changes until Tailwind goes 1.0.0-stable. No need to beta release, as any of these changes are already possible with the cli options (the whole point of the project, no?).

Win10 - ngtw build --purge throws an error

When I run ngtw build --purge, I receive the following error:

Error: EISDIR: illegal operation on a directory, read

Notably, it works fine when it's running a build on Azure, but not when running locally on my Win10 machine.

Sass/Scss

Hello,

How can I use scss ?

I tried using following options in config:

sourceCSS: './src/scss/app.scss', outputCSS: './src/scss/app.css',

But it doesnt works, It just copy scss with my imports.

Tailwind v1.7.0 Experimental features enable

As new release brings features like deprecation notifications and experimental flags, it'd be great to be able to enable them.

When I tried to install tailwind via postcss-loader, I saw some messages in console, that some experimental features were enabled, but there is silence. Another example, I can't make work extendedSpacingScale feature, according to release notes it should bring more classes into tailwind.css.

Upd: removeDeprecatedGapUtilities: true works correctly, but can anyone check for extendedSpacingScale? Or it might be better to wait until it becomes stable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.