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

Add @config support #9405

Merged
merged 3 commits into from Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Allow negating utilities using min/max/clamp ([#9237](https://github.com/tailwindlabs/tailwindcss/pull/9237))
- Add new `collapse` utility for `visibility: collapse` ([#9181](https://github.com/tailwindlabs/tailwindcss/pull/9181))
- Allow resolving content paths relative to the config file ([#9396](https://github.com/tailwindlabs/tailwindcss/pull/9396))
- Add `@config` support ([#9405](https://github.com/tailwindlabs/tailwindcss/pull/9405))

### Fixed

Expand Down
224 changes: 224 additions & 0 deletions integrations/tailwindcss-cli/tests/integration.test.js
@@ -1,3 +1,4 @@
let fs = require('fs')
let $ = require('../../execute')
let { css, html, javascript } = require('../../syntax')

Expand Down Expand Up @@ -88,6 +89,108 @@ describe('static build', () => {
`
)
})

it('can read from a config file from an @config directive', async () => {
await writeInputFile('index.html', html`<div class="bg-yellow"></div>`)
await writeInputFile(
'index.css',
css`
@config "./tailwind.config.js";
@tailwind base;
@tailwind components;
@tailwind utilities;
`
)
await writeInputFile(
'tailwind.config.js',
javascript`
module.exports = {
content: {
relative: true,
files: ['./index.html'],
},
theme: {
extend: {
colors: {
yellow: '#ff0',
}
},
},
corePlugins: {
preflight: false,
},
}
`
)

await $('node ../../lib/cli.js -i ./src/index.css -o ./dist/main.css', {
env: { NODE_ENV: 'production' },
})

expect(await readOutputFile('main.css')).toIncludeCss(
css`
.bg-yellow {
--tw-bg-opacity: 1;
background-color: rgb(255 255 0 / var(--tw-bg-opacity));
}
`
)
})

it('can read from a config file from an @config directive inside an @import from postcss-import', async () => {
await fs.promises.mkdir('./src/config', { recursive: true })

await writeInputFile('index.html', html`<div class="bg-yellow"></div>`)
await writeInputFile(
'config/myconfig.css',
css`
@config "../tailwind.config.js";
`
)
await writeInputFile(
'index.css',
css`
@import './config/myconfig';
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
`
)
await writeInputFile(
'tailwind.config.js',
javascript`
module.exports = {
content: {
relative: true,
files: ['./index.html'],
},
theme: {
extend: {
colors: {
yellow: '#ff0',
}
},
},
corePlugins: {
preflight: false,
},
}
`
)

await $('node ../../lib/cli.js -i ./src/index.css -o ./dist/main.css', {
env: { NODE_ENV: 'production' },
})

expect(await readOutputFile('main.css')).toIncludeCss(
css`
.bg-yellow {
--tw-bg-opacity: 1;
background-color: rgb(255 255 0 / var(--tw-bg-opacity));
}
`
)
})
})

describe('watcher', () => {
Expand Down Expand Up @@ -381,4 +484,125 @@ describe('watcher', () => {

return runningProcess.stop()
})

test('listens for changes to the @config directive', async () => {
await writeInputFile('index.html', html`<div class="bg-yellow"></div>`)
await writeInputFile(
'index.css',
css`
@config "./tailwind.config.js";
@tailwind base;
@tailwind components;
@tailwind utilities;
`
)
await writeInputFile(
'tailwind.config.js',
javascript`
module.exports = {
content: {
relative: true,
files: ['./index.html'],
},
theme: {
extend: {
colors: {
yellow: '#ff0',
}
},
},
corePlugins: {
preflight: false,
},
}
`
)
await writeInputFile(
'tailwind.2.config.js',
javascript`
module.exports = {
content: {
relative: true,
files: ['./index.html'],
},
theme: {
extend: {
colors: {
yellow: '#ff7',
}
},
},
corePlugins: {
preflight: false,
},
}
`
)

let runningProcess = $('node ../../lib/cli.js -i ./src/index.css -o ./dist/main.css -w')
await runningProcess.onStderr(ready)

expect(await readOutputFile('main.css')).toIncludeCss(
css`
.bg-yellow {
--tw-bg-opacity: 1;
background-color: rgb(255 255 0 / var(--tw-bg-opacity));
}
`
)

await writeInputFile(
'index.css',
css`
@config "./tailwind.2.config.js";
@tailwind base;
@tailwind components;
@tailwind utilities;
`
)
await runningProcess.onStderr(ready)

expect(await readOutputFile('main.css')).toIncludeCss(
css`
.bg-yellow {
--tw-bg-opacity: 1;
background-color: rgb(255 255 119 / var(--tw-bg-opacity));
}
`
)

await writeInputFile(
'tailwind.2.config.js',
javascript`
module.exports = {
content: {
relative: true,
files: ['./index.html'],
},
theme: {
extend: {
colors: {
yellow: '#fff',
}
},
},
corePlugins: {
preflight: false,
},
}
`
)
await runningProcess.onStderr(ready)

expect(await readOutputFile('main.css')).toIncludeCss(
css`
.bg-yellow {
--tw-bg-opacity: 1;
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
}
`
)

return runningProcess.stop()
})
})