57 Commits

Author SHA1 Message Date
Robin Malfait
1868eb6177
Fix @apply order regression (in addComponents, addUtilities, ...) (#7232)
* ensure to partition `@apply` rules generated by addComponents, addUtilities, ...

* update changelog
2022-01-27 13:16:44 +01:00
Jordan Pittman
a891867a2f
Fix consecutive builds with at apply producing different CSS (#6999)
* Partition at rules before building context

* remove unnecessary logic

* Update changelog

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2022-01-10 12:36:14 -05:00
Robin Malfait
fe08e919dc
Ensure @apply works consistently with or without @layer (#6938)
* partition nodes as soon as possible

Time to write another story on `@apply`...

When we write code like this:

```css
.a {
  @apply b;
}

.b {
  @apply uppercase;
  color: red;
}
```

Then we create 2 Nodes in our context to keep track of. One has
identifier `a`, the other has identifier `b`. However, when we have an
`@apply` and it contains multiple declarations/atrules, then we have to
split up the (aka partition) node into multiple nodes so that we can
guarantee the correct expected sort order.

This means that the above example technically looks like this:

```css
.a {
  @apply b;
}

.b {
  @apply uppercase;
}

.b {
  color: red;
}
```

If this was your input, then we would still have 1 node for identifier
'a', but we would have 2 nodes for identifier 'b'.

As mentioned earlier, this is important to guarantee the correct order,
here is an example:

```css
.b {
  @apply md:font-bold xl:font-normal; /* Here we can sort by our
  internal rules. This means that the `md` comes before `xl`. */
}
```

... however

```css
.b {
  @apply xl:font-normal; /* This now exists _before_ the example below */
}

.b {
  @apply md:font-bold; /* Because we respect the order of the user's css */
}
```

So to guarantee the order when doing this:
```css
.b {
  @apply xl:font-normal;
  @apply lg:font-normal;
}
```

We also split this up into 2 nodes like this:
```css
.b {
  @apply xl:font-normal;
}
.b {
  @apply lg:font-normal;
}
```

The tricky part is that now only 1 empty `.b` node exists in our context
because we partitioned the orginal node into multiple nodes and moved
the children to the new nodes and because they are new nodes it means
that they have a different identity.

This partitioning used to happen in the expandApplyAtRules code, but
this is a bit too late because the context has already been filled at
this time. Instead, we move the code more to the front, as if you wrote
those separated blocks yourself. Now the code to inject those nodes into
the context happens in a single spot instead of multiple places.

Another good part about this is that we have better consistency between
each layer because it turns out that these two examples generated
different results...

```css
.a {
  @apply b;
}
.b {
  @apply uppercase;
  color: red;
}
```

... is different compared to:

```css
@tailwind components;
@layer components {
  .a {
    @apply b;
  }
  .b {
    @apply uppercase;
    color: red;
  }
}
```

Even if both `a` and `b` are being used in one of your content paths...
Yeah.. *sigh*

* add more `@apply` related tests

* update changelog

* remove support for basic nesting (leftover)

* remove leftover todo

This has been fixed already
2022-01-07 16:41:01 +01:00
Gary Mathews
722232cb2e
Allow all classes for @apply (#6580)
* Always include css with apply in context

* Use let

We use it more consistently

* Remove early return

To match the style of the surrounding code

* Don't return layer directives

They do not need to be returned here. If it's needed in the future its easy enough to add it back.

* Use let

* Update changelog

* fix typo

And re-format comments

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2022-01-04 14:23:10 +01:00
Robin Malfait
ea6f14a499
Dedupe duplicate properties (#5830)
* add `collapseDuplicateDeclarations`

This will allow us to remove duplicate declarations. This occurs when
you are using `@apply` for example.

The reason I implemented it as a separate step, is because this doesn't
only happen for `@apply`, but it also happens if you do something like:

```js
addComponents({ '.btn-blue, .btm-red': { padding: '10px' } })
```

So instead of tracking down every place this is happening, it now
happens at the very end.

* use new plugin in processTailwindFeatures

* add/update tests by removing duplicate declarations

* update changelog
2021-10-21 11:54:23 +02:00
Robin Malfait
ee0f32908d
Ensure we log flag notices (#5726) 2021-10-07 12:52:53 +02:00
Robin Malfait
c30a32e430
Drop unused tailwindDirectives argument (#5624) 2021-09-28 12:00:27 +02:00
Robin Malfait
14d49a9fd5
Warn when nesting is detected (#5489)
* warn when nesting is detected

* add todo for improving warning messages
2021-09-16 14:13:45 +02:00
Robin Malfait
691ed02f63
Remove AOT (#5340)
* make `jit` mode the default when no mode is specified

* unify JIT and AOT codepaths

* ensure `Object.entries` on undefined doesn't break

It could be that sometimes you don't have values in your config (e.g.: `presets: []`), this in turn will break some plugins where we assume we have a value.

* drop AOT specific tests

These tests are all covered by JIT mode already and were AOT specific.

* simplify tests, and add a few

Some of the tests were written for AOT specifically, some were missing. We also updated the way we write those tests, essentially making Tailwind a blackbox, by testing against the final output.
Now that JIT mode is the default, this is super fast because we only generate what is used, instead of partially testing in a 3MB file or building it all, then purging.

* add some todo's to make sure we warn in a few cases

* make `darkMode: 'media'`, the default

This also includes moving dark mode tests to its own dedicated file.

* remove PostCSS 7 compat mode

* update CLI to be JIT-first

* fix integration tests

This is not a _real_ fix, but it does solve the broken test for now.

* warn when using @responsive or @variants

* remove the JIT preview warning

* remove AOT-only code paths

* remove all `mode: 'jit'` blocks

Also remove `variants: {}` since they are not useful in `JIT` mode
anymore.

* drop unused dependencies

* rename `purge` to `content`

* remove static CDN builds

* mark `--purge` as deprecated in the CLI

This will still work, but a warning will be printed and it won't show up
in the `--help` output.

* cleanup nesting plugin

We don't have to duplicate it anymore since there is no PostCSS 7
version anymore.

* make sure integration tests run in band

* cleanup folder structure

* make sure nesting folder is available

* simplify resolving of purge/content information
2021-09-01 17:13:59 +02:00
Brad Cornes
243e8814d8
Resolve purge paths relative to the current working directory (#4655)
* resolve purge paths relative to cwd

* simplify test
2021-06-15 16:37:04 -04:00
Brad Cornes
a3db3a4700
Register PurgeCSS content as PostCSS dependencies (#4543)
* add `glob` property to `dir-dependency` messages

* Add `glob` to `dir-dependency` messages

* register purge content as postcss dependencies
2021-06-03 05:41:32 -04:00
Adam Wathan
1849e35f14 Refactor internals to decouple watch strategies and extract IO
Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2021-05-26 09:43:05 -04:00
Brad Cornes
477dd06ec3
Resolve purge paths (#4214)
* resolve purge paths

* add test for purgecss pattern resolution

* resolve purgecss patterns relative to the config file if there is one

* account for raw content when transforming purgecss options

* append test name to postcss `from` option in purge tests
fixes tests hanging

* add test for relative purge path resolution in JIT mode
2021-05-07 13:46:19 -04:00
Adam Wathan
82f4eaa683 Ignore unknown types when hashing config 2021-05-06 13:16:32 -04:00
Robin Malfait
eac11cf57d
Performance improvements + memory leak fix (#3032)
* fix memory leak

* add optional condition to hasAtRule

* use known tree to handle `@apply` when required `@tailwind` at rules exists

Otherwise we will generate the lookup tree.

* only generate the missing `@tailwind` atrules when using `@apply`

* update perf config to reflect 2.0 changes

* update changelog

* ensure lookup tree is correctly cached based on used tailwind atrules
2020-12-11 15:03:49 +01:00
Adam Wathan
0e4870c8d7 Remove unused import 2020-10-18 15:43:50 -04:00
Adam Wathan
7376d7c8b1 Enable dark mode 2020-10-18 15:43:50 -04:00
Adam Wathan
e3ed12782f Update prettier 2020-10-16 13:30:06 -04:00
Adam Wathan
7e1a1e0b35 Warn users who still have target in their config file 2020-10-15 15:21:06 -04:00
Adam Wathan
b299b6fbe1
Support new presets key + extending core plugins config (#2474)
* WIP

* Support array for Tailwind config

* Drop array format for `presets` key instead

* Update changelog
2020-10-08 11:21:39 -04:00
Adam Wathan
6a9c3e7886
Register dark mode plugin outside of resolveConfig code path (#2368) 2020-09-11 10:15:39 -04:00
Adam Wathan
2d090feb98 Only log purge notice once per process 2020-08-19 10:56:51 -04:00
Adam Wathan
ef149cfafb Optimize rebuilds in long-running processes 2020-08-19 10:21:26 -04:00
Adam Wathan
4228cf22be Don't issue duplicate flag notices in long running processes 2020-08-18 21:14:10 -04:00
Adam Wathan
cef0b84abf Reorganize prototype code 2020-08-14 12:23:28 -04:00
Adam Wathan
8646c94dd5 Prepend a shadow lookup table when no @tailwind rules are in the tree 2020-08-13 20:16:56 -04:00
Adam Wathan
c252e33254 Get shadow lookup working-ish with new apply approach 2020-08-13 12:14:26 -04:00
Adam Wathan
61635f4884 Co-locate feature flag utilities 2020-08-06 16:02:09 -04:00
Adam Wathan
1ac5874732 Add scaffolding for future/experimental flags, with WIP new color palette as example 2020-08-05 14:02:43 -04:00
Adam Wathan
ab12ab9636 Ensure Tailwind PostCSS plugins receive unaltered plugin output 2020-07-21 10:21:57 -04:00
Adam Wathan
5b19a41195 Convert layers to control comments before processing @apply rules 2020-07-15 09:41:19 -04:00
Adam Wathan
b69e46cc1b Rename buckets to layers, handle copying layer information to responsive variants 2020-07-15 09:25:22 -04:00
Adam Wathan
4169bb1ac2 Simplify implementation, remove unnecessary new features 2020-07-14 20:53:18 -04:00
Adam Wathan
64b6c955c7 Improve PurgeCSS integration
- Add better Pug support
- Add "modes", with "all" and "conservative" by default
- Allow passing options through to PurgeCSS
- Rename `paths` to `content` to match PurgeCSS
2020-04-28 09:51:27 -04:00
Adam Wathan
ec0b7a2be1 Integrate PurgeCSS directly into Tailwind 2020-04-27 21:24:49 -04:00
Adam Wathan
95bb283a69 Rename defaultPlugins to corePlugins 2019-02-01 12:32:50 -05:00
Adam Wathan
fd22dea5ad Always load core plugins by default 2019-02-01 12:32:50 -05:00
Adam Wathan
2f9172cf8d Update every plugin to accept its config as a parameter 2019-02-01 12:32:50 -05:00
Adam Wathan
ffae87148d Revert "Allow plugins to register new config variables" 2019-02-01 12:32:04 -05:00
Adam Wathan
5ea8bbe798 Allow plugins to register new config variables 2019-02-01 12:32:04 -05:00
Adam Wathan
adc5d2597c Remove unnecessary parameter 2019-01-14 15:43:12 -05:00
Adam Wathan
060d23439d Remove code obsoleted by upgrading PostCSS 2019-01-14 15:43:12 -05:00
Adam Wathan
f01d79f76b Add a comment to explain performance optimization 2019-01-14 15:43:12 -05:00
Adam Wathan
5ade923fa4 Fix tests and lint warnings 2019-01-14 15:43:12 -05:00
Adam Wathan
eeb42cd6bb Provide our own rawCache to avoid performance issues 2019-01-14 15:43:12 -05:00
Adam Wathan
5b3d6d8861 Port objectPosition module to plugin, conditionally load plugins based on modules config 2019-01-14 15:43:12 -05:00
Adam Wathan
027b69c7e8 Port width and whitespace modules to plugins 2019-01-14 15:43:12 -05:00
Adam Wathan
6352843cde Port zIndex module to default plugin 2019-01-14 15:43:12 -05:00
Adam Wathan
146b984617 Accept plugins as separate processPlugins arg 2019-01-14 15:43:12 -05:00
Adam Wathan
7201c4f51b Rename lazyConfig to getConfig 2018-07-16 08:37:23 -04:00