Skip to content

Add @content support to tailwindcss#14079

Merged
philipp-spiess merged 12 commits intofeat/add-content-supportfrom
feat/add-content-support-to-core
Aug 1, 2024
Merged

Add @content support to tailwindcss#14079
philipp-spiess merged 12 commits intofeat/add-content-supportfrom
feat/add-content-support-to-core

Conversation

@RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Jul 29, 2024

This PR adds @content support to tailwindcss's core package. We will handle the @content and call the onContentPath function when it's encountered.

The @tailwindcss/cli, @tailwindcss/vite and @tailwindcss/postcss packages have to implement the onContentPath such that the necessary globs are scanned and watchers should be setup with this information.

Example usage:

@content "../../packages/my-sibling-package/src/components/*.tsx";

If you are in a monorepo setup, then you could point to other packages if you want. Another common use case is for Laravel projects if you want to point to Laravel blade files since they won't be covered by Vite's module graph:

/* ./resources/css/app.css */
@content "../views/*.blade.php"

Note: all globs are relative to the current file you are in.

@RobinMalfait RobinMalfait force-pushed the feat/add-content-support-to-core branch from d69d260 to cd37016 Compare July 29, 2024 17:05
@RobinMalfait RobinMalfait force-pushed the feat/add-content-support branch from 1ee39a6 to 6d39204 Compare July 30, 2024 08:30
@RobinMalfait RobinMalfait force-pushed the feat/add-content-support-to-core branch from 2710729 to 105293e Compare July 30, 2024 08:48
@philipp-spiess philipp-spiess force-pushed the feat/add-content-support branch from 6d39204 to b078327 Compare July 30, 2024 12:06
@RobinMalfait RobinMalfait force-pushed the feat/add-content-support-to-core branch from 97683da to 1c1bbca Compare July 30, 2024 15:28
Copy link
Contributor

@thecrypticace thecrypticace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The windows tests are failing but I think that's addressed by the other PR so this looks good afaict

This is not only about auto content detection anymore, but it's testing
the `scan_dir` functionality.

`scan_dir` contains auto content detection and will handle passed in
globs.
Integrations have to implement the `onContentPath` to know about the
globs found in `@content`.
All integrations will make use of this, so let's get rid of the option
entirely.
On the Rust side, we will make sure to optimize the `globs` and merge it
with the generated globs from the auto content detection.
This means that we don't need special casing of the absolute paths. And
more importantly, we don't need to worry about Windows in this case
either.
This now means that all the globs passed in are a `GlobEntry`, which
contains the `base` and the `glob`.
@RobinMalfait RobinMalfait force-pushed the feat/add-content-support-to-core branch from 1c1bbca to fb8228e Compare July 30, 2024 16:06
@philipp-spiess philipp-spiess merged commit f2cd0b3 into feat/add-content-support Aug 1, 2024
@philipp-spiess philipp-spiess deleted the feat/add-content-support-to-core branch August 1, 2024 16:00
philipp-spiess pushed a commit that referenced this pull request Aug 2, 2024
This PR adds `@content` support to `tailwindcss`'s core package. We will
handle the `@content` and call the `onContentPath` function when it's
encountered.

The `@tailwindcss/cli`, `@tailwindcss/vite` and `@tailwindcss/postcss`
packages have to implement the `onContentPath` such that the necessary
globs are scanned and watchers should be setup with this information.

Example usage:

```css
@content "../../packages/my-sibling-package/src/components/*.tsx";
```

If you are in a monorepo setup, then you could point to other packages
if you want. Another common use case is for Laravel projects if you want
to point to Laravel blade files since they won't be covered by Vite's
module graph:

```css
/* ./resources/css/app.css */
@content "../views/*.blade.php"
```

Note: all globs are relative to the current file you are in.
philipp-spiess pushed a commit that referenced this pull request Aug 5, 2024
This PR adds `@content` support to `tailwindcss`'s core package. We will
handle the `@content` and call the `onContentPath` function when it's
encountered.

The `@tailwindcss/cli`, `@tailwindcss/vite` and `@tailwindcss/postcss`
packages have to implement the `onContentPath` such that the necessary
globs are scanned and watchers should be setup with this information.

Example usage:

```css
@content "../../packages/my-sibling-package/src/components/*.tsx";
```

If you are in a monorepo setup, then you could point to other packages
if you want. Another common use case is for Laravel projects if you want
to point to Laravel blade files since they won't be covered by Vite's
module graph:

```css
/* ./resources/css/app.css */
@content "../views/*.blade.php"
```

Note: all globs are relative to the current file you are in.
RobinMalfait added a commit that referenced this pull request Aug 7, 2024
This PR adds `@content` support to `tailwindcss`'s core package. We will
handle the `@content` and call the `onContentPath` function when it's
encountered.

The `@tailwindcss/cli`, `@tailwindcss/vite` and `@tailwindcss/postcss`
packages have to implement the `onContentPath` such that the necessary
globs are scanned and watchers should be setup with this information.

Example usage:

```css
@content "../../packages/my-sibling-package/src/components/*.tsx";
```

If you are in a monorepo setup, then you could point to other packages
if you want. Another common use case is for Laravel projects if you want
to point to Laravel blade files since they won't be covered by Vite's
module graph:

```css
/* ./resources/css/app.css */
@content "../views/*.blade.php"
```

Note: all globs are relative to the current file you are in.
RobinMalfait added a commit that referenced this pull request Aug 7, 2024
This PR is an umbrella PR where we will add support for the new
`@source` directive. This will allow you to add explicit content glob
patterns if you want to look for Tailwind classes in other files that
are not automatically detected yet.

Right now this is an addition to the existing auto content detection
that is automatically enabled in the `@tailwindcss/postcss` and
`@tailwindcss/cli` packages. The `@tailwindcss/vite` package doesn't use
the auto content detection, but uses the module graph instead.

From an API perspective there is not a lot going on. There are only a
few things that you have to know when using the `@source` directive, and
you probably already know the rules:

1. You can use multiple `@source` directives if you want.
2. The `@source` accepts a glob pattern so that you can match multiple
files at once
3. The pattern is relative to the current file you are in
4. The pattern includes all files it is matching, even git ignored files
1. The motivation for this is so that you can explicitly point to a
`node_modules` folder if you want to look at `node_modules` for whatever
reason.
6. Right now we don't support negative globs (starting with a `!`) yet,
that will be available in the near future.

Usage example:

```css
/* ./src/input.css */
@import "tailwindcss";
@source "../laravel/resources/views/**/*.blade.php";
@source "../../packages/monorepo-package/**/*.js";
```

It looks like the PR introduced a lot of changes, but this is a side
effect of all the other plumbing work we had to do to make this work.
For example:

1. We added dedicated integration tests that run on Linux and Windows in
CI (just to make sure that all the `path` logic is correct)
2. We Have to make sure that the glob patterns are always correct even
if you are using `@import` in your CSS and use `@source` in an imported
file. This is because we receive the flattened CSS contents where all
`@import`s are inlined.
3. We have to make sure that we also listen for changes in the files
that match any of these patterns and trigger a rebuild.

PRs:

- [x] #14063
- [x] #14085
- [x] #14079
- [x] #14067
- [x] #14076
- [x] #14080
- [x] #14127
- [x] #14135

Once all the PRs are merged, then this umbrella PR can be merged. 

> [!IMPORTANT]  
> Make sure to merge this without rebasing such that each individual PR
ends up on the main branch.

---------

Co-authored-by: Philipp Spiess <hello@philippspiess.com>
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
mark-tomlinson-dev pushed a commit to sugarcube-org/scanner-temp that referenced this pull request Aug 19, 2025
This PR is an umbrella PR where we will add support for the new
`@source` directive. This will allow you to add explicit content glob
patterns if you want to look for Tailwind classes in other files that
are not automatically detected yet.

Right now this is an addition to the existing auto content detection
that is automatically enabled in the `@tailwindcss/postcss` and
`@tailwindcss/cli` packages. The `@tailwindcss/vite` package doesn't use
the auto content detection, but uses the module graph instead.

From an API perspective there is not a lot going on. There are only a
few things that you have to know when using the `@source` directive, and
you probably already know the rules:

1. You can use multiple `@source` directives if you want.
2. The `@source` accepts a glob pattern so that you can match multiple
files at once
3. The pattern is relative to the current file you are in
4. The pattern includes all files it is matching, even git ignored files
1. The motivation for this is so that you can explicitly point to a
`node_modules` folder if you want to look at `node_modules` for whatever
reason.
6. Right now we don't support negative globs (starting with a `!`) yet,
that will be available in the near future.

Usage example:

```css
/* ./src/input.css */
@import "tailwindcss";
@source "../laravel/resources/views/**/*.blade.php";
@source "../../packages/monorepo-package/**/*.js";
```

It looks like the PR introduced a lot of changes, but this is a side
effect of all the other plumbing work we had to do to make this work.
For example:

1. We added dedicated integration tests that run on Linux and Windows in
CI (just to make sure that all the `path` logic is correct)
2. We Have to make sure that the glob patterns are always correct even
if you are using `@import` in your CSS and use `@source` in an imported
file. This is because we receive the flattened CSS contents where all
`@import`s are inlined.
3. We have to make sure that we also listen for changes in the files
that match any of these patterns and trigger a rebuild.

PRs:

- [x] tailwindlabs/tailwindcss#14063
- [x] tailwindlabs/tailwindcss#14085
- [x] tailwindlabs/tailwindcss#14079
- [x] tailwindlabs/tailwindcss#14067
- [x] tailwindlabs/tailwindcss#14076
- [x] tailwindlabs/tailwindcss#14080
- [x] tailwindlabs/tailwindcss#14127
- [x] tailwindlabs/tailwindcss#14135

Once all the PRs are merged, then this umbrella PR can be merged. 

> [!IMPORTANT]  
> Make sure to merge this without rebasing such that each individual PR
ends up on the main branch.

---------

Co-authored-by: Philipp Spiess <hello@philippspiess.com>
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants