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

Support loading config files via @config #14239

Merged
merged 42 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
7f5ee2c
Use `resolveConfig` to normalize plugins
thecrypticace Aug 19, 2024
542a2a3
Add support for presets
thecrypticace Aug 19, 2024
a54bf8a
Allow resolve config to take in optional paths alongside configs
thecrypticace Aug 22, 2024
d2dbc3f
Add config helper
thecrypticace Aug 22, 2024
08a7501
Load config files via `@config` directive
thecrypticace Aug 22, 2024
75576d0
Merge sources from config files
thecrypticace Aug 22, 2024
0a9edd3
Allow configuring dark mode from configs
thecrypticace Aug 22, 2024
444b238
Add config test
thecrypticace Aug 22, 2024
40caaa7
Work on theme value merging
thecrypticace Aug 22, 2024
81e0ee9
Ensure CSS variants and utilities always take precedence
thecrypticace Aug 22, 2024
4fa5945
Format code
thecrypticace Aug 22, 2024
4228903
prettier
thecrypticace Aug 22, 2024
921cf8e
wip
thecrypticace Aug 22, 2024
74b607e
Handle inline theme keys in `resolveWith`
thecrypticace Aug 22, 2024
967ea3b
Update tests
thecrypticace Aug 22, 2024
67c1dc1
Upgrade merged theme keys from `colors.*` to `color-*`
thecrypticace Aug 22, 2024
6c0b9b1
Add integration tests
thecrypticace Aug 22, 2024
2f5b108
update test
thecrypticace Aug 22, 2024
f4abaed
wip
thecrypticace Aug 23, 2024
ffa0028
Detect changes to the config file and plugins for the CLI
philipp-spiess Aug 23, 2024
f7e1c84
Add the @tailwindcss/node module to handle shared node specific depen…
philipp-spiess Aug 23, 2024
97d6103
WIP
philipp-spiess Aug 23, 2024
07e79aa
Fix js config file and plugin dependnecy rebuilds for vite
philipp-spiess Aug 23, 2024
cdadd63
Revert change to integrations/postcss/index.test.ts
philipp-spiess Aug 23, 2024
294a4b1
Fix esm cache hook for esm usage with vitest
philipp-spiess Aug 23, 2024
7d7c0f7
Only reset the require cache for build dependencies
philipp-spiess Aug 23, 2024
439f8b0
Add the same workaround for postcss esm
philipp-spiess Aug 23, 2024
7d97d94
Make getModuleDependencies async
thecrypticace Aug 23, 2024
3ab5c82
Make the ESM cache hook ESM-only
thecrypticace Aug 23, 2024
359fb31
Don't block on module dependency resolution
philipp-spiess Aug 26, 2024
e75e99a
Rename to applyConfigToTheme
philipp-spiess Aug 26, 2024
b6f434f
Rename resolveInternal to extractConfigs
philipp-spiess Aug 26, 2024
8661ec2
Add change log and improve error messages
philipp-spiess Aug 26, 2024
b1b960d
Do not register ESM hook in Bun
philipp-spiess Aug 29, 2024
44ad8ce
Fix typo
thecrypticace Sep 1, 2024
3a8dd7a
Adress PR feedback
philipp-spiess Sep 2, 2024
0da9884
move common `loadPlugin` and `loadConfig` to `@tailwindcss/node`
RobinMalfait Sep 2, 2024
b7266fb
ignore dynamic import
RobinMalfait Sep 2, 2024
aa32928
inline `esm-cache-hook`, and generate CJS and ESM separately
RobinMalfait Sep 2, 2024
46c304b
Update CHANGELOG.md
RobinMalfait Sep 2, 2024
16d174e
loop over files instead of characters
RobinMalfait Sep 2, 2024
eb23b17
cleanup CHANGELOG
RobinMalfait Sep 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Add new standalone builds of Tailwind CSS v4 ([#14270](https://github.com/tailwindlabs/tailwindcss/pull/14270))
- Support JavaScript configuration files using `@config` ([#14239](https://github.com/tailwindlabs/tailwindcss/pull/14239))

### Fixed

Expand Down
191 changes: 191 additions & 0 deletions integrations/cli/config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
import { candidate, css, html, js, json, test } from '../utils'

test(
'Config files (CJS)',
{
fs: {
'package.json': json`
{
"dependencies": {
"tailwindcss": "workspace:^",
"@tailwindcss/cli": "workspace:^"
}
}
`,
'index.html': html`
<div class="text-primary"></div>
`,
'tailwind.config.js': js`
module.exports = {
theme: {
extend: {
colors: {
primary: 'blue',
},
},
},
}
`,
'src/index.css': css`
@import 'tailwindcss';
@config '../tailwind.config.js';
`,
},
},
async ({ fs, exec }) => {
await exec('pnpm tailwindcss --input src/index.css --output dist/out.css')

await fs.expectFileToContain('dist/out.css', [
//
candidate`text-primary`,
])
},
)

test(
'Config files (ESM)',
{
fs: {
'package.json': json`
{
"dependencies": {
"tailwindcss": "workspace:^",
"@tailwindcss/cli": "workspace:^"
}
}
`,
'index.html': html`
<div class="text-primary"></div>
`,
'tailwind.config.mjs': js`
export default {
theme: {
extend: {
colors: {
primary: 'blue',
},
},
},
}
`,
'src/index.css': css`
@import 'tailwindcss';
@config '../tailwind.config.mjs';
`,
},
},
async ({ fs, exec }) => {
await exec('pnpm tailwindcss --input src/index.css --output dist/out.css')

await fs.expectFileToContain('dist/out.css', [
//
candidate`text-primary`,
])
},
)

test(
'Config files (CJS, watch mode)',
{
fs: {
'package.json': json`
{
"dependencies": {
"tailwindcss": "workspace:^",
"@tailwindcss/cli": "workspace:^"
}
}
`,
'index.html': html`
<div class="text-primary"></div>
`,
'tailwind.config.js': js`
const myColor = require('./my-color')
module.exports = {
theme: {
extend: {
colors: {
primary: myColor,
},
},
},
}
`,
'my-color.js': js`module.exports = 'blue'`,
'src/index.css': css`
@import 'tailwindcss';
@config '../tailwind.config.js';
`,
},
},
async ({ fs, spawn }) => {
await spawn('pnpm tailwindcss --input src/index.css --output dist/out.css --watch')

await fs.expectFileToContain('dist/out.css', [
//
candidate`text-primary`,
'color: blue',
])

await fs.write('my-color.js', js`module.exports = 'red'`)

await fs.expectFileToContain('dist/out.css', [
//
candidate`text-primary`,
'color: red',
])
},
)

test(
'Config files (MJS, watch mode)',
{
fs: {
'package.json': json`
{
"dependencies": {
"tailwindcss": "workspace:^",
"@tailwindcss/cli": "workspace:^"
}
}
`,
'index.html': html`
<div class="text-primary"></div>
`,
'tailwind.config.mjs': js`
import myColor from './my-color.mjs'
export default {
theme: {
extend: {
colors: {
primary: myColor,
},
},
},
}
`,
'my-color.mjs': js`export default 'blue'`,
'src/index.css': css`
@import 'tailwindcss';
@config '../tailwind.config.mjs';
`,
},
},
async ({ fs, spawn }) => {
await spawn('pnpm tailwindcss --input src/index.css --output dist/out.css --watch')

await fs.expectFileToContain('dist/out.css', [
//
candidate`text-primary`,
'color: blue',
])

await fs.write('my-color.mjs', js`export default 'red'`)

await fs.expectFileToContain('dist/out.css', [
//
candidate`text-primary`,
'color: red',
])
},
)
Loading