Skip to content

Commit cf8596b

Browse files
authored
Include default config by default in presets (#2662)
1 parent a350ef0 commit cf8596b

File tree

4 files changed

+68
-12
lines changed

4 files changed

+68
-12
lines changed

__tests__/customConfig.test.js

+62-9
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,17 @@ test('the default config can be overridden using the presets key', () => {
218218
{
219219
theme: {
220220
extend: {
221-
colors: {
222-
black: 'black',
221+
minHeight: {
222+
24: '24px',
223223
},
224-
backgroundColor: theme => theme('colors'),
225224
},
226225
},
227-
corePlugins: ['backgroundColor'],
226+
corePlugins: ['minHeight'],
227+
variants: { minHeight: [] },
228228
},
229229
],
230230
theme: {
231-
extend: { colors: { white: 'white' } },
231+
extend: { minHeight: { 48: '48px' } },
232232
},
233233
}),
234234
])
@@ -240,11 +240,62 @@ test('the default config can be overridden using the presets key', () => {
240240
)
241241
.then(result => {
242242
const expected = `
243-
.bg-black {
244-
background-color: black;
243+
.min-h-0 {
244+
min-height: 0;
245245
}
246-
.bg-white {
247-
background-color: white;
246+
.min-h-24 {
247+
min-height: 24px;
248+
}
249+
.min-h-48 {
250+
min-height: 48px;
251+
}
252+
.min-h-full {
253+
min-height: 100%;
254+
}
255+
.min-h-screen {
256+
min-height: 100vh;
257+
}
258+
`
259+
260+
expect(result.css).toMatchCss(expected)
261+
})
262+
})
263+
264+
test('the default config can be removed by using an empty presets key in a preset', () => {
265+
return postcss([
266+
tailwind({
267+
presets: [
268+
{
269+
presets: [],
270+
theme: {
271+
extend: {
272+
minHeight: {
273+
24: '24px',
274+
},
275+
},
276+
},
277+
corePlugins: ['minHeight'],
278+
variants: { minHeight: [] },
279+
},
280+
],
281+
theme: {
282+
extend: { minHeight: { 48: '48px' } },
283+
},
284+
}),
285+
])
286+
.process(
287+
`
288+
@tailwind utilities
289+
`,
290+
{ from: undefined }
291+
)
292+
.then((result) => {
293+
const expected = `
294+
.min-h-24 {
295+
min-height: 24px;
296+
}
297+
.min-h-48 {
298+
min-height: 48px;
248299
}
249300
`
250301

@@ -257,13 +308,15 @@ test('presets can have their own presets', () => {
257308
tailwind({
258309
presets: [
259310
{
311+
presets: [],
260312
theme: {
261313
colors: { red: '#dd0000' },
262314
},
263315
},
264316
{
265317
presets: [
266318
{
319+
presets: [],
267320
theme: {
268321
colors: {
269322
transparent: 'transparent',

__tests__/purgeUnusedStyles.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ const config = {
5858
},
5959
}
6060

61+
delete config.presets
62+
6163
function assertPurged(result) {
6264
expect(result.css).not.toContain('.bg-red-600')
6365
expect(result.css).not.toContain('.w-1\\/3')

src/util/getAllConfigs.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import standardFontWeights from '../flagged/standardFontWeights'
99
import additionalBreakpoint from '../flagged/additionalBreakpoint'
1010
import { flatMap, get } from 'lodash'
1111

12-
export default function getAllConfigs(config, defaultPresets = [defaultConfig]) {
13-
const configs = flatMap([...get(config, 'presets', defaultPresets)].reverse(), preset => {
14-
return getAllConfigs(preset, [])
12+
export default function getAllConfigs(config) {
13+
const configs = flatMap([...get(config, 'presets', [defaultConfig])].reverse(), preset => {
14+
return getAllConfigs(preset)
1515
})
1616

1717
const features = {

stubs/defaultConfig.stub.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
prefix: '',
99
important: false,
1010
separator: ':',
11+
presets: [],
1112
theme: {
1213
screens: {
1314
sm: '640px',

0 commit comments

Comments
 (0)