Skip to content

feat: generate apps with Tailwind CSS 4 - #92

Merged
NathanWalker merged 14 commits into
mainfrom
feat/tailwind-4
Nov 25, 2026
Merged

NathanWalker merged 14 commits into
mainfrom
feat/tailwind-4

Conversation

@NathanWalker

@NathanWalker NathanWalker commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #90 (feat/nx-24). This will be retargeted to main once #90 merges.

What changed

The app generator (vanilla and angular) now sets up Tailwind CSS 4 in place of Tailwind CSS 3.

Package Before After
@nativescript/tailwind ^2.1.0 ^4.1.0
tailwindcss ~3.4.0 ^4.3.0

Per framework template (files_vanilla, files_angular):

  • tailwind.config.js is removed. Tailwind 4 is configured in CSS, and @nativescript/tailwind 4 needs no JS config and no postcss.config.js.
  • .gitignore no longer carries the !tailwind.config.js exception.
  • src/app.css replaces the @tailwind base/components/utilities directives and carries over the two settings the old config file held:
/*
 * Tailwind CSS without Preflight: its browser resets (e.g. * { margin: 0; padding: 0 })
 * would match every NativeScript view.
 */
@layer theme, base, components, utilities;
@import 'tailwindcss/theme.css' layer(theme);
@import 'tailwindcss/utilities.css' layer(utilities);

/* NativeScript sets .ns-dark on root and modal views */
@custom-variant dark (&:where(.ns-dark, .ns-dark *));

updatePluginDependencies still adds @nativescript/tailwind and tailwindcss to the root devDependencies; only its comment changed. In tools/update-versions.ts, both packages stay on the hold policy, because a major bump of either one has to be made together with the other. The caret ranges still pick up new 4.x minors, so hold only freezes the floor.

Why it looks like this

  • CSS entry. The @nativescript/tailwind README says: "Import Tailwind: Add the following to your app.css or app.scss: @import 'tailwindcss';" and "Manual PostCSS configuration is typically not required for Tailwind CSS v4. @nativescript/tailwind handles the necessary setup automatically." Its nativescript.webpack.js adds postcss-preset-env, @tailwindcss/postcss, @nativescript/tailwind and @csstools/postcss-is-pseudo-class to the css/scss postcss-loader rules through chainWebpack. @nativescript/webpack 5 applies it automatically because the app package.json lists @nativescript/tailwind.
  • Preflight stays off. The v3 template set corePlugins: { preflight: false }. Tailwind 4 has no such option. Tailwind's Preflight docs say: "If you'd like to completely disable Preflight … you can do so by importing only the parts of Tailwind that you need", which means theme.css and utilities.css without preflight.css. I first tried the plain @import 'tailwindcss' entry, and the prepared bundle then contained *, ::after, ::before, ::backdrop, ::file-selector-button { margin: 0; padding: 0 } and button, input, select, … { background-color: transparent; border-radius: 0; color: inherit; … }. Those rules would restyle every NativeScript view.
  • dark: keyed to .ns-dark. The v3 template used darkMode: ['class', '.ns-dark']. Tailwind's dark mode docs: "If you want your dark theme to be driven by a CSS selector instead of the prefers-color-scheme media query, override the dark variant to use your custom selector: @custom-variant dark (&:where(.dark, .dark *));". @nativescript/tailwind 4.1.0 (#227) fixed the :where() expansion of exactly this variant. Before 4.1.0 it matched every descendant of .ns-dark, which is why the floor is ^4.1.0.
  • No content globs. Tailwind 4 detects sources automatically from the build's working directory (the app root under ns/webpack) and respects .gitignore. That replaces the v3 content: ['./src/**/*.{css,xml,html,vue,svelte,ts,tsx}']. The e2e run below shows classes from .xml and Angular .html templates being picked up.
  • Compatibility. @nativescript/tailwind 4.1.0 depends on @tailwindcss/postcss ^4.0.0, has a peer dependency on postcss ^8, and is built against @nativescript/webpack ^5.0.8. Its 4.1.0 release notes describe it as "Tailwind v4 parity with @nativescript/core 9.x". The generators already install @nativescript/core ~9.1.0 and @nativescript/webpack ~5.0.0 (resolves to 5.0.42), so no other version had to move. The official NativeScript app templates use the same pairing (template-blank-vue: @nativescript/tailwind ^4.0.0, tailwindcss ^4.0.0, app.css with @import "tailwindcss").

Existing workspaces are not touched. The generator only affects newly generated apps.

Tests

New it.each(['vanilla', 'angular'])('should set up tailwind 4 for %s') in application.spec.ts. It asserts the 4.x versions, the app package.json devDependency, the new app.css imports (and that the full tailwindcss/preflight.css entry is absent), the .ns-dark custom variant, no @tailwind directives, no tailwind.config.js and no .gitignore exception. Without the change, it fails on expected '~3.4.0' to match /^\^4\./.

  • npm test: 5 files, 28 tests pass (was 26)
  • npm run lint: 0 errors, 47 warnings (unchanged baseline)
  • npm run build: passes
  • npx prettier --check on the changed files: clean

End-to-end verification

I packed the plugin (npm pack of dist/packages/nx) and installed it into a fresh, non-TS-solution Nx 24.0.7 workspace (TypeScript 6.0.3). npm resolved tailwindcss 4.3.5, @tailwindcss/postcss 4.3.5, @nativescript/tailwind 4.1.0 and @nativescript/webpack 5.0.42.

npx nx g @nativescript/nx:app apps/demo  --framework=vanilla --linter=eslint --no-interactive
npx nx g @nativescript/nx:app apps/ngapp --framework=angular --linter=eslint --no-interactive
# added: text-red-500 bg-blue-200 dark:text-green-400 to src/main-page.xml (vanilla)
#        and features/home/home.component.html (angular)
npx nx run nativescript-demo:prepare  --platform=ios      # Project successfully prepared (ios)
npx nx run nativescript-demo:prepare  --platform=android  # Project successfully prepared (android)
npx nx run nativescript-ngapp:prepare --platform=ios      # Project successfully prepared (ios)
npx nx run nativescript-ngapp:prepare --platform=android  # Project successfully prepared (android)
npx nx run-many -t lint                                   # 0 errors (3 template warnings)

All four prepared bundles contain the compiled rules:
apps/nativescript-demo/platforms/ios/nativescriptdemo/app/bundle.mjs, apps/nativescript-demo/platforms/android/app/src/main/assets/app/bundle.mjs, apps/nativescript-ngapp/platforms/ios/nativescriptngapp/app/bundle.mjs and apps/nativescript-ngapp/platforms/android/app/src/main/assets/app/bundle.mjs.

{"type":"rule","selectors":[".text-red-500"],"declarations":[{"type":"declaration","property":"color","value":"var(--color-red-500)"}
{"type":"rule","selectors":[".dark\\:text-green-400.ns-dark",".ns-dark .dark\\:text-green-400"],"declarations":[{"type":"declaration","property":"color","value":"var(--color-green-400)"}
"property":"--color-red-500","value":"rgb(251, 44, 54)"      (on .ns-root, .ns-modal)

None of the bundles contains a Preflight rule. The vanilla sheet holds only .bg-blue-200, .dark\:text-green-400…, .ns-root/.ns-modal (theme variables), .p-20, .px-4, .text-center and .text-red-500. The angular sheet also has a *, ::before, ::after, ::backdrop rule that only declares --tw-* custom properties (Tailwind 4's @property fallback) and sets no layout properties.

Angular under TypeScript 6 defaults

The first Angular run hit TypeScript 6's strict default in template files from #90. That is fixed on #90 (d4a460f), which is merged into this branch. Re-run with no strict key in the workspace tsconfig.base.json: nativescript-ngapp:prepare succeeds on iOS and Android, and both bundles contain .text-red-500 { color: var(--color-red-500) }.

- nx and @nx/* 23.1.0 -> 24.0.7, nx-cloud 19.1.3 -> 19.1.5; typescript stays 6.0.3, vitest stays 3.2.x
- nx migrate: set affected.legacy, convert the removed @nx/eslint:lint executor to the @nx/eslint/plugin inferred target
- exclude generator template dirs from @nx/eslint/plugin so their package.json files are not picked up as projects
- library spec: Nx 24 lint is inferred via @nx/eslint/plugin instead of an explicit executor target
Nx 24 turns eslintFilePatterns into an explicit `eslint <glob>` command that fails on the brace pattern when no spec files exist. Let @nx/eslint/plugin infer `eslint .` and add flat-config ignores for platforms/, hooks/ and references.d.ts instead.
The triple-slash references in references.d.ts fail @typescript-eslint/triple-slash-reference, so a freshly generated library did not lint clean.
Without a TTY, the configuration and platform prompts crashed with ERR_USE_AFTER_CLOSE. A missing configuration now falls back to no configuration, the same as answering "No" interactively and the same as Nx's own behavior without -c, and logs the existing warning. A missing platform has no sensible default, so it fails with an error pointing at --platform or --silent (which already defaults to iOS).
workspace-lint, workspace-generator, affected:apps, affected:libs and help no longer exist, so npm run lint failed. Use run-many/affected -t, show projects and graph, including for the affected:<target> and dep-graph aliases that still work. Drop start (no project has a serve target).
The vanilla template has no src/main.ts; its entry is src/app.ts.
Both app templates ship tailwind.config.js and an app.css with tailwind directives, but only the Angular app added @nativescript/tailwind and tailwindcss to the root package.json, so a vanilla app failed to prepare.
@nativescript/core, types, ios and android ~9.0.0 -> ~9.1.0 (latest 9.1.4 / 9.1.4 / 9.1.1 / 9.1.2). @nativescript/webpack ~5.0.0 is already current; @nativescript/tailwind stays on the 2.x line with tailwindcss 3.
nx.json keeps the Nx 24 eslint plugin and affected.legacy settings and takes the release config and nx-release-publish target default from main. package-lock.json is this branch's Nx 24 lockfile; npm install against the merged package.json leaves it unchanged.
nx release reads the current version from packages/nx/package.json, so a prerelease bump on main yields 24.0.0-next.N and a manual major release yields 24.0.0.
Generated apps now install @nativescript/tailwind ^4.1.0 and
tailwindcss ^4.3.0. Tailwind 4 is configured in CSS, so
tailwind.config.js is gone and app.css carries the settings it held:

- import tailwindcss/theme.css and tailwindcss/utilities.css instead of
  the full 'tailwindcss' entry, keeping Preflight disabled as
  corePlugins.preflight: false did (its * { margin: 0; padding: 0 } and
  button resets would otherwise reach every NativeScript view)
- @custom-variant dark keys dark: to the .ns-dark class, as
  darkMode: ['class', '.ns-dark'] did

Content scanning uses Tailwind 4's automatic source detection.
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 84a76ed8-fdc4-4405-81a5-687705c95554

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…6 strict defaults

TypeScript 6 enables strict by default, so getItem() returning a possibly undefined find() result and signal<Item>(null) failed the generated app's webpack build.
@NathanWalker
NathanWalker changed the base branch from feat/nx-24 to main November 25, 2026 23:26
@NathanWalker
NathanWalker merged commit 722eb22 into main Nov 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant