Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Commit ef94e9c

Browse files
committed
Collapse adjacent media queries
1 parent 7bdae2f commit ef94e9c

File tree

2 files changed

+23
-40
lines changed

2 files changed

+23
-40
lines changed

src/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,29 @@ module.exports = (pluginOptions = {}) => {
11941194
},
11951195
evaluateTailwindFunctions(context.tailwindConfig),
11961196
substituteScreenAtRules(context.tailwindConfig),
1197+
1198+
// Collapse adjacent media queries
1199+
function (root) {
1200+
let currentRule = null
1201+
root.each((node) => {
1202+
if (node.type !== 'atrule') {
1203+
currentRule = null
1204+
return
1205+
}
1206+
1207+
if (currentRule === null) {
1208+
currentRule = node
1209+
return
1210+
}
1211+
1212+
if (node.params === currentRule.params) {
1213+
currentRule.append(node.nodes)
1214+
node.remove()
1215+
} else {
1216+
currentRule = node
1217+
}
1218+
})
1219+
},
11971220
]).process(root, { from: undefined })
11981221
},
11991222
env.DEBUG &&

src/index.test.css

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
--tw-bg-opacity: 1;
2626
background-color: rgba(16, 185, 129, var(--tw-bg-opacity));
2727
}
28-
}
29-
@media (min-width: 640px) {
3028
.apply-test:focus:nth-child(even) {
3129
--tw-bg-opacity: 1;
3230
background-color: rgba(251, 207, 232, var(--tw-bg-opacity));
@@ -355,43 +353,31 @@ div {
355353
.sm\:container {
356354
width: 100%;
357355
}
358-
}
359-
@media (min-width: 640px) {
360356
@media (min-width: 640px) {
361357
.sm\:container {
362358
max-width: 640px;
363359
}
364360
}
365-
}
366-
@media (min-width: 640px) {
367361
@media (min-width: 768px) {
368362
.sm\:container {
369363
max-width: 768px;
370364
}
371365
}
372-
}
373-
@media (min-width: 640px) {
374366
@media (min-width: 1024px) {
375367
.sm\:container {
376368
max-width: 1024px;
377369
}
378370
}
379-
}
380-
@media (min-width: 640px) {
381371
@media (min-width: 1280px) {
382372
.sm\:container {
383373
max-width: 1280px;
384374
}
385375
}
386-
}
387-
@media (min-width: 640px) {
388376
@media (min-width: 1536px) {
389377
.sm\:container {
390378
max-width: 1536px;
391379
}
392380
}
393-
}
394-
@media (min-width: 640px) {
395381
.sm\:ordinal,
396382
.sm\:slashed-zero,
397383
.sm\:lining-nums,
@@ -408,18 +394,12 @@ div {
408394
font-variant-numeric: var(--tw-ordinal) var(--tw-slashed-zero) var(--tw-numeric-figure)
409395
var(--tw-numeric-spacing) var(--tw-numeric-fraction);
410396
}
411-
}
412-
@media (min-width: 640px) {
413397
.sm\:tabular-nums {
414398
--tw-numeric-spacing: tabular-nums;
415399
}
416-
}
417-
@media (min-width: 640px) {
418400
.sm\:text-center {
419401
text-align: center;
420402
}
421-
}
422-
@media (min-width: 640px) {
423403
@media (prefers-reduced-motion: no-preference) {
424404
.group:active .sm\:motion-safe\:group-active\:focus\:opacity-10:focus {
425405
opacity: 0.1;
@@ -430,65 +410,45 @@ div {
430410
.md\:container {
431411
width: 100%;
432412
}
433-
}
434-
@media (min-width: 768px) {
435413
@media (min-width: 640px) {
436414
.md\:container {
437415
max-width: 640px;
438416
}
439417
}
440-
}
441-
@media (min-width: 768px) {
442418
@media (min-width: 768px) {
443419
.md\:container {
444420
max-width: 768px;
445421
}
446422
}
447-
}
448-
@media (min-width: 768px) {
449423
@media (min-width: 1024px) {
450424
.md\:container {
451425
max-width: 1024px;
452426
}
453427
}
454-
}
455-
@media (min-width: 768px) {
456428
@media (min-width: 1280px) {
457429
.md\:container {
458430
max-width: 1280px;
459431
}
460432
}
461-
}
462-
@media (min-width: 768px) {
463433
@media (min-width: 1536px) {
464434
.md\:container {
465435
max-width: 1536px;
466436
}
467437
}
468-
}
469-
@media (min-width: 768px) {
470438
.md\:shadow-sm {
471439
--tw-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
472440
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000),
473441
var(--tw-shadow);
474442
}
475-
}
476-
@media (min-width: 768px) {
477443
.md\:opacity-50 {
478444
opacity: 0.5;
479445
}
480-
}
481-
@media (min-width: 768px) {
482446
.md\:text-center {
483447
text-align: center;
484448
}
485-
}
486-
@media (min-width: 768px) {
487449
.md\:hover\:opacity-20:hover {
488450
opacity: 0.2;
489451
}
490-
}
491-
@media (min-width: 768px) {
492452
@media (prefers-reduced-motion: no-preference) {
493453
.md\:motion-safe\:hover\:transition:hover {
494454
transition-property: background-color, border-color, color, fill, stroke, opacity, box-shadow,

0 commit comments

Comments
 (0)