Skip to content

Commit f57025f

Browse files
committed
only split stylesheets when migrating Tailwind CSS v3 projects
1 parent 892fdc7 commit f57025f

File tree

1 file changed

+25
-23
lines changed
  • packages/@tailwindcss-upgrade/src

1 file changed

+25
-23
lines changed

packages/@tailwindcss-upgrade/src/index.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -210,31 +210,33 @@ async function run() {
210210
)
211211

212212
// Split up stylesheets (as needed)
213-
try {
214-
await splitStylesheets(stylesheets)
215-
} catch (e: any) {
216-
error(`${e?.message ?? e}`, { prefix: '↳ ' })
217-
}
213+
if (version.isMajor(3)) {
214+
try {
215+
await splitStylesheets(stylesheets)
216+
} catch (e: any) {
217+
error(`${e?.message ?? e}`, { prefix: '↳ ' })
218+
}
218219

219-
// Cleanup `@import "…" layer(utilities)`
220-
for (let sheet of stylesheets) {
221-
for (let importRule of sheet.importRules) {
222-
if (!importRule.raws.tailwind_injected_layer) continue
223-
let importedSheet = stylesheets.find(
224-
(sheet) => sheet.id === importRule.raws.tailwind_destination_sheet_id,
225-
)
226-
if (!importedSheet) continue
227-
228-
// Only remove the `layer(…)` next to the import if any of the children
229-
// contain `@utility`. Otherwise `@utility` will not be top-level.
230-
if (
231-
!importedSheet.containsRule((node) => node.type === 'atrule' && node.name === 'utility')
232-
) {
233-
continue
234-
}
220+
// Cleanup `@import "…" layer(utilities)`
221+
for (let sheet of stylesheets) {
222+
for (let importRule of sheet.importRules) {
223+
if (!importRule.raws.tailwind_injected_layer) continue
224+
let importedSheet = stylesheets.find(
225+
(sheet) => sheet.id === importRule.raws.tailwind_destination_sheet_id,
226+
)
227+
if (!importedSheet) continue
228+
229+
// Only remove the `layer(…)` next to the import if any of the children
230+
// contain `@utility`. Otherwise `@utility` will not be top-level.
231+
if (
232+
!importedSheet.containsRule((node) => node.type === 'atrule' && node.name === 'utility')
233+
) {
234+
continue
235+
}
235236

236-
// Make sure to remove the `layer(…)` from the `@import` at-rule
237-
importRule.params = importRule.params.replace(/ layer\([^)]+\)/, '').trim()
237+
// Make sure to remove the `layer(…)` from the `@import` at-rule
238+
importRule.params = importRule.params.replace(/ layer\([^)]+\)/, '').trim()
239+
}
238240
}
239241
}
240242

0 commit comments

Comments
 (0)