Skip to content

Commit 3e8218c

Browse files
authored
feat: support tailwindcss v4 (#194)
1 parent a145afd commit 3e8218c

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

Diff for: nativescript.webpack.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = (webpack) => {
1111
const addPostCSSPlugins = (options = {}) => {
1212
return webpack.merge(options, {
1313
postcssOptions: {
14-
plugins: ["tailwindcss", "@nativescript/tailwind", "@csstools/postcss-is-pseudo-class"],
14+
plugins: ["postcss-preset-env", "@tailwindcss/postcss", "@nativescript/tailwind", "@csstools/postcss-is-pseudo-class"],
1515
},
1616
});
1717
};

Diff for: package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@
3535
"license": "MIT",
3636
"devDependencies": {
3737
"@nativescript/webpack": "^5.0.8",
38-
"postcss": "8.4.16",
39-
"tailwindcss": "^3.4.0"
38+
"postcss": "^8.4.16",
39+
"tailwindcss": "^4.0.0"
4040
},
4141
"dependencies": {
4242
"@hookun/parse-animation-shorthand": "^0.1.4",
43-
"@csstools/postcss-is-pseudo-class": "4.0.4"
43+
"@csstools/postcss-is-pseudo-class": "~5.0.1",
44+
"@tailwindcss/postcss": "^4.0.0",
45+
"postcss-preset-env": "^10.1.3"
4446
},
4547
"peerDependencies": {
4648
"postcss": "^8.0.0"

Diff for: src/removeUnsupported.js

+25
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ module.exports = (options = { debug: false }) => {
5050
return rule.remove();
5151
}
5252

53+
// replace :root and :host pseudo selector, introduced in Tailwind 4+ with .ns-root for var handling.
54+
if (rule.selector.includes(":root") || rule.selector.includes(":host")) {
55+
rule.selectors = rule.selectors.map((selector) =>
56+
selector.replace(/:root/, ".ns-root").replace(/:host/, ".ns-root")
57+
);
58+
}
59+
5360
// remove rules with unsupported selectors
5461
if (!isSupportedSelector(rule.selector)) {
5562
return rule.remove();
@@ -99,6 +106,18 @@ module.exports = (options = { debug: false }) => {
99106
}
100107
}
101108

109+
// invalid with core 8.8+ at moment
110+
// Note: could be supported at somepoint
111+
if (decl.prop === "placeholder-color" && decl.value?.includes("color-mix")) {
112+
return decl.remove();
113+
}
114+
115+
// invalid with core 8.8+ at moment
116+
// Note: could be supported at somepoint
117+
if (decl.value?.includes("currentColor")) {
118+
return decl.remove();
119+
}
120+
102121
// replace vertical-align: middle
103122
// with vertical-align: center
104123
if (decl.prop === "vertical-align") {
@@ -219,6 +238,12 @@ const supportedProperties = {
219238
"margin-left": true,
220239
"margin-right": true,
221240
"margin-top": true,
241+
"margin-block": true,
242+
"margin-block-start": true,
243+
"margin-block-end": true,
244+
"margin-inline": true,
245+
"margin-inline-start": true,
246+
"margin-inline-end": true,
222247
"min-height": true,
223248
"min-width": true,
224249
"off-background-color": true,

0 commit comments

Comments
 (0)