|
1 | 1 | import { createRequire } from "module"; |
| 2 | + |
2 | 3 | const require = createRequire(import.meta.url); |
3 | 4 |
|
| 5 | +// PostCSS plugin order matters: |
| 6 | +// 1. postcss-preset-env |
| 7 | +// Run this first so it only sees user-authored CSS, not Tailwind output. |
| 8 | +// If it runs last, its is/not-pseudo-class and cascade-layers polyfills can |
| 9 | +// chew on Tailwind v4's `:not(#\#)` specificity chains and silently |
| 10 | +// mangle utilities like `w-[400]`. |
| 11 | +// |
| 12 | +// 2. @tailwindcss/postcss |
| 13 | +// Tailwind v4 expansion. Pass `optimize: false` because this plugin enables |
| 14 | +// its built-in lightningcss optimizer whenever |
| 15 | +// `process.env.NODE_ENV === "production"`, which `vite build` sets even for |
| 16 | +// `mode: development` debug bundles. |
| 17 | +// lightningcss "normalizes" unitless values by appending `px` |
| 18 | +// (`width: 400` -> `width: 400px`). |
| 19 | +// |
| 20 | +// 3. @nativescript/tailwind |
| 21 | +// Apply NativeScript-specific selector/property rewrites: |
| 22 | +// `:root` -> `.ns-root, .ns-modal`, `rem` -> `px`, and removal of |
| 23 | +// unsupported declarations. |
| 24 | +// |
| 25 | +// 4. @csstools/postcss-is-pseudo-class |
| 26 | +// Flatten `:is()` and `:not()` because NativeScript's selector matcher does |
| 27 | +// not support `:is()` natively. |
4 | 28 | let postcssConfig = "./postcss.config.js"; |
5 | 29 |
|
6 | 30 | try { |
7 | | - const twV4 = require("@tailwindcss/postcss"); |
| 31 | + const tailwindcssPostcss = require("@tailwindcss/postcss"); |
8 | 32 | const nsTailwind = require("@nativescript/tailwind"); |
9 | | - const postCssOklabFunction = require('@csstools/postcss-oklab-function'); |
10 | | - postcssConfig = { plugins: [twV4, nsTailwind, postCssOklabFunction({ preserve: false })] }; |
11 | | -} catch (e2) { |
| 33 | + const postcssPresetEnv = require("postcss-preset-env"); |
| 34 | + const postcssIsPseudoClass = require("@csstools/postcss-is-pseudo-class"); |
| 35 | + |
| 36 | + postcssConfig = { |
| 37 | + plugins: [ |
| 38 | + postcssPresetEnv(), |
| 39 | + tailwindcssPostcss({ optimize: false }), |
| 40 | + nsTailwind, |
| 41 | + postcssIsPseudoClass(), |
| 42 | + ], |
| 43 | + }; |
| 44 | +} catch (e) { |
12 | 45 | console.warn( |
13 | | - "Inline PostCSS unavailable, falling back to ./postcss.config.js" |
| 46 | + "[ns-tailwind] Inline PostCSS chain unavailable, falling back to ./postcss.config.js. Cause:", |
| 47 | + e?.message ?? e, |
14 | 48 | ); |
15 | 49 | } |
16 | 50 |
|
17 | | -export default () => { |
18 | | - return { |
19 | | - css: { |
20 | | - postcss: postcssConfig, |
21 | | - }, |
22 | | - }; |
23 | | -}; |
| 51 | +export default () => ({ |
| 52 | + css: { |
| 53 | + postcss: postcssConfig, |
| 54 | + }, |
| 55 | +}); |
0 commit comments