• Stars
    star
    473
  • Rank 92,832 (Top 2 %)
  • Language
    Elixir
  • License
    MIT License
  • Created almost 3 years ago
  • Updated 3 months ago

Reviews

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

Repository Details

An installer for tailwind

Tailwind

CI

Mix tasks for installing and invoking tailwindcss via the stand-alone tailwindcss cli

Note: The stand-alone Tailwind client bundles first-class Tailwind packages within the precompiled executable. For third-party Tailwind plugin support (e.g. DaisyUI), the node package must be used. See the Tailwind Node.js installation instructions if you require third-party plugin support.

Installation

If you are going to build assets in production, then you add tailwind as dependency on all environments but only start it in dev:

def deps do
  [
    {:tailwind, "~> 0.2", runtime: Mix.env() == :dev}
  ]
end

However, if your assets are precompiled during development, then it only needs to be a dev dependency:

def deps do
  [
    {:tailwind, "~> 0.2", only: :dev}
  ]
end

Once installed, change your config/config.exs to pick your tailwind version of choice:

config :tailwind, version: "3.2.4"

Now you can install tailwind by running:

$ mix tailwind.install

or if your platform isn't officially supported by Tailwind, you can supply a third party path to the binary the installer wants (beware that we cannot guarantee the compatibility of any third party executable):

$ mix tailwind.install https://people.freebsd.org/~dch/pub/tailwind/v3.2.6/tailwindcss-freebsd-x64

And invoke tailwind with:

$ mix tailwind default

The executable is kept at _build/tailwind-TARGET. Where TARGET is your system target architecture.

Profiles

The first argument to tailwind is the execution profile. You can define multiple execution profiles with the current directory, the OS environment, and default arguments to the tailwind task:

config :tailwind,
  version: "3.2.4",
  default: [
    args: ~w(
      --config=tailwind.config.js
      --input=css/app.css
      --output=../priv/static/assets/app.css
    ),
    cd: Path.expand("../assets", __DIR__)
  ]

When mix tailwind default is invoked, the task arguments will be appended to the ones configured above. Note profiles must be configured in your config/config.exs, as tailwind runs without starting your application (and therefore it won't pick settings in config/runtime.exs).

Adding to Phoenix

To add tailwind to an application using Phoenix, you will need Phoenix v1.6+ and the following steps.

First add it as a dependency in your mix.exs:

def deps do
  [
    {:phoenix, "~> 1.6"},
    {:tailwind, "~> 0.1.8", runtime: Mix.env() == :dev}
  ]
end

Also, in mix.exs, add tailwind to the assets.deploy alias for deployments (with the --minify option):

"assets.deploy": ["tailwind default --minify", ..., "phx.digest"]

Now let's change config/config.exs to tell tailwind to use configuration in assets/tailwind.config.js for building our css bundle into priv/static/assets. We'll also give it our assets/css/app.css as our css entry point:

config :tailwind,
  version: "3.2.4",
  default: [
    args: ~w(
      --config=tailwind.config.js
      --input=css/app.css
      --output=../priv/static/assets/app.css
    ),
    cd: Path.expand("../assets", __DIR__)
  ]

Make sure the "assets" directory from priv/static is listed in the :only option for Plug.Static in your lib/my_app_web/endpoint.ex

If your Phoenix application is using an umbrella structure, you should specify the web application's asset directory in the configuration:

config :tailwind,
  version: "3.2.4",
  default: [
    args: ...,
    cd: Path.expand("../apps/<folder_ending_with_web>/assets", __DIR__)
  ]

For development, we want to enable watch mode. So find the watchers configuration in your config/dev.exs and add:

  tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]}

Note we are enabling the file system watcher.

Finally, run the command:

$ mix tailwind.install

This command installs Tailwind and updates your assets/css/app.css and assets/js/app.js with the necessary changes to start using Tailwind right away. It also generates a default configuration file called assets/tailwind.config.js for you. This is the file we referenced when we configured tailwind in config/config.exs. See mix help tailwind.install to learn more.

License

Copyright (c) 2022 Chris McCord. Copyright (c) 2021 Wojtek Mach, JosΓ© Valim.

tailwind source code is licensed under the MIT License.

More Repositories

1

phoenix

Peace of mind from prototype to production
Elixir
21,268
star
2

phoenix_live_view

Rich, real-time user experiences with server-rendered HTML
Elixir
6,172
star
3

phoenix_live_dashboard

Realtime dashboard with metrics, request logging, plus storage, OS and VM insights
Elixir
1,998
star
4

flame

Fleeting Lambda Application for Modular Execution: auto scale parts of your existing app with a single function call
Elixir
891
star
5

phoenix_pubsub

Distributed PubSub and Presence platform for the Phoenix Framework
Elixir
640
star
6

phoenix_guides

User guides for the Phoenix web development framework.
500
star
7

phoenix_ecto

Phoenix and Ecto integration with support for concurrent acceptance testing
Elixir
473
star
8

phoenix_html

Building blocks for working with HTML in Phoenix
Elixir
401
star
9

phoenix_live_reload

Provides live-reload functionality for Phoenix
Elixir
315
star
10

firenest

Elixir
271
star
11

esbuild

An installer for esbuild
Elixir
269
star
12

dns_cluster

Simple DNS clustering for distributed Elixir nodes
Elixir
188
star
13

phoenix_pubsub_redis

The Redis PubSub adapter for the Phoenix framework
Elixir
175
star
14

vscode-phoenix

Syntax highlighting support for Phoenix templates in Visual Studio Code.
160
star
15

plds

CLI version of Phoenix LiveDashboard
Elixir
86
star
16

websock

A specification for Elixir apps to service WebSocket connections
Elixir
75
star
17

phoenix_view

View abstraction for Phoenix v1.0-v1.6
Elixir
65
star
18

tree-sitter-heex

HEEx grammer for Tree-sitter
JavaScript
51
star
19

phoenix_template

Template rendering for Phoenix
Elixir
49
star
20

ex_conf

Simple Elixir Configuration Management
Elixir
36
star
21

websock_adapter

Implementation of the WebSock specification for servers
Elixir
30
star
22

archives

Holds archives for released Phoenix versions
27
star
23

phoenix_html_helpers

Collection of helpers to generate and manipulate HTML contents
Elixir
15
star
24

phoenix_site

CSS
13
star
25

media

Phoenix Related Media
10
star
26

node_checker

Elixir
3
star