Skip to content

Commit 7a7303b

Browse files
authored
Merge pull request #1162 from tailwindcss/allow-plugins-to-modify-config
Allow plugins to add their own config file to be resolved with the user's custom config
2 parents 5ba0cc1 + 2fa0d4e commit 7a7303b

8 files changed

+633
-16
lines changed

.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"extends": ["eslint-config-postcss", "prettier"],
1010
"plugins": ["prettier"],
1111
"rules": {
12+
"no-unused-vars": [2, {"args": "all", "argsIgnorePattern": "^_"}],
1213
"prettier/prettier": [
1314
"error",
1415
{

__tests__/processPlugins.test.js

+82-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ test('plugins can create utilities with object syntax', () => {
4747
object-fit: cover
4848
}
4949
}
50-
`)
50+
`)
5151
})
5252

5353
test('plugins can create utilities with arrays of objects', () => {
@@ -1206,3 +1206,84 @@ test('prefix will prefix all classes in a selector', () => {
12061206
}
12071207
`)
12081208
})
1209+
1210+
test('plugins can be provided as an object with a handler function', () => {
1211+
const { components, utilities } = processPlugins(
1212+
[
1213+
{
1214+
handler({ addUtilities }) {
1215+
addUtilities({
1216+
'.object-fill': {
1217+
'object-fit': 'fill',
1218+
},
1219+
'.object-contain': {
1220+
'object-fit': 'contain',
1221+
},
1222+
'.object-cover': {
1223+
'object-fit': 'cover',
1224+
},
1225+
})
1226+
},
1227+
},
1228+
],
1229+
makeConfig()
1230+
)
1231+
1232+
expect(components.length).toBe(0)
1233+
expect(css(utilities)).toMatchCss(`
1234+
@variants {
1235+
.object-fill {
1236+
object-fit: fill
1237+
}
1238+
.object-contain {
1239+
object-fit: contain
1240+
}
1241+
.object-cover {
1242+
object-fit: cover
1243+
}
1244+
}
1245+
`)
1246+
})
1247+
1248+
test('plugins can provide a config but no handler', () => {
1249+
const { components, utilities } = processPlugins(
1250+
[
1251+
{
1252+
config: {
1253+
prefix: 'tw-',
1254+
},
1255+
},
1256+
{
1257+
handler({ addUtilities }) {
1258+
addUtilities({
1259+
'.object-fill': {
1260+
'object-fit': 'fill',
1261+
},
1262+
'.object-contain': {
1263+
'object-fit': 'contain',
1264+
},
1265+
'.object-cover': {
1266+
'object-fit': 'cover',
1267+
},
1268+
})
1269+
},
1270+
},
1271+
],
1272+
makeConfig()
1273+
)
1274+
1275+
expect(components.length).toBe(0)
1276+
expect(css(utilities)).toMatchCss(`
1277+
@variants {
1278+
.object-fill {
1279+
object-fit: fill
1280+
}
1281+
.object-contain {
1282+
object-fit: contain
1283+
}
1284+
.object-cover {
1285+
object-fit: cover
1286+
}
1287+
}
1288+
`)
1289+
})

0 commit comments

Comments
 (0)