Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto source detection improvements #14820

Merged
merged 18 commits into from
Oct 29, 2024

Conversation

RobinMalfait
Copy link
Member

This PR introduces a new source(…) argument and improves on the existing @source. The goal of this PR is to make the automatic source detection configurable, let's dig in.

By default, we will perform automatic source detection starting at the current working directory. Auto source detection will find plain text files (no binaries, images, ...) and will ignore git-ignored files.

If you want to start from a different directory, you can use the new source(…) next to the @import "tailwindcss/utilities" layer(utilities) source(…).

E.g.:

/* ./src/styles/index.css */
@import 'tailwindcss/utilities' layer(utilities) source('../../');

Most people won't split their source files, and will just use the simple @import "tailwindcss";, because of this reason, you can use source(…) on the import as well:

E.g.:

/* ./src/styles/index.css */
@import 'tailwindcss' source('../../');

Sometimes, you want to rely on auto source detection, but also want to look in another directory for source files. In this case, yuo can use the @source directive:

/* ./src/index.css */
@import 'tailwindcss';

/* Look for `blade.php` files in `../resources/views` */
@source '../resources/views/**/*.blade.php';

However, you don't need to specify the extension, instead you can just point the directory and all the same automatic source detection rules will apply.

/* ./src/index.css */
@import 'tailwindcss';

@source '../resources/views';

If, for whatever reason, you want to disable the default source detection feature entirely, and only want to rely on very specific glob patterns you define, then you can disable it via source(none).

/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);

/* Only look at .blade.php files, nothing else  */
@source "../resources/views/**/*.blade.php";

Note: even with source(none), if your @source points to a directory, then auto source detection will still be performed in that directory. If you don't want that, then you can simply add explicit files in the globs as seen in the previous example.

/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);

/* Run auto source detection in `../resources/views` */
@source "../resources/views";

Noticed some files weren't properly formatted, this fixes that by using:

- `npm run format`
- `cargo clippy --fix`
We used to list `core` instead of `oxide`, this should make sure that
building Oxide works if we make changes in `oxide/`.
Typically we wrap the `exec(…)` in integration tests with a console log
when focusing on a test. Let's do this by default now.
Whenever we dump the generated CSS file, it will contain a license
header. If we later bump the version, then the tests start failing. In
the tests we don't care about the header so let's ignore it there.
@RobinMalfait RobinMalfait force-pushed the feat/auto-source-detection-improvements branch 3 times, most recently from f0cf898 to 58a8a4c Compare October 29, 2024 14:37
And handle the `source(…)` on the `@tailwind utilities` at-rule. In
addition, we also track the `@tailwind utilities` node while traversing
it once. This allows us to skip an entire walk.
We will be applying auto source detection on normal sources found via
`@source` as well. This means that we don't need a distinction between
sources and detect sources.

The only difference would be that in the clients (`@tailwindcss/vite`,
`@tailwindcss/postcss` and `@tailwindcss/cli`), you pass everything as a
single array of sources.
@RobinMalfait RobinMalfait force-pushed the feat/auto-source-detection-improvements branch from 9835a1d to b766949 Compare October 29, 2024 16:52
@thecrypticace thecrypticace marked this pull request as ready for review October 29, 2024 20:19
@thecrypticace thecrypticace requested a review from a team as a code owner October 29, 2024 20:19
@RobinMalfait RobinMalfait enabled auto-merge (squash) October 29, 2024 20:31
@RobinMalfait RobinMalfait merged commit d68a780 into next Oct 29, 2024
1 check passed
@RobinMalfait RobinMalfait deleted the feat/auto-source-detection-improvements branch October 29, 2024 20:33
RobinMalfait added a commit that referenced this pull request Oct 30, 2024
This PR fixes Windows related path issues after merging #14820

---------

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
@xcrap
Copy link

xcrap commented Nov 2, 2024

I have a Laravel project where I separated the frontend and backend.

I have the following paths for example.

Backend:
/resources/components/admin/*
/resources/views/admin/*
/resources/js/custom.js

Frontend:
/resources/components/website/*
/resources/view/website/*
/resources/js/admin.js

I was loading individual tailwind.config.js for each part, can we load multiple sources ?
Does the @config "../../tailwind.admin.config.js"; still exists in v4 or it's gone.

Thanks.

@philipp-spiess
Copy link
Member

@xcrap @config still works in v4 but it's recommended you move the config to a CSS file instead. If you have any issues with it, feel free to create a new issue, it seems unrelated to this PR and since this PR is already closed, you might not get a response otherwise (I just happen to see it because I was going over closed PRs after my vacation)

@xcrap
Copy link

xcrap commented Nov 4, 2024

@xcrap @config still works in v4 but it's recommended you move the config to a CSS file instead. If you have any issues with it, feel free to create a new issue, it seems unrelated to this PR and since this PR is already closed, you might not get a response otherwise (I just happen to see it because I was going over closed PRs after my vacation)

Thank you, I'm using configs in the CSS, thanks for the reply :)

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.

5 participants