Repository navigation
feat: generate apps with Tailwind CSS 4 - #92
Merged
Merged
Conversation
- 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.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
The app generator (vanilla and angular) now sets up Tailwind CSS 4 in place of Tailwind CSS 3.
@nativescript/tailwind^2.1.0^4.1.0tailwindcss~3.4.0^4.3.0Per framework template (
files_vanilla,files_angular):tailwind.config.jsis removed. Tailwind 4 is configured in CSS, and@nativescript/tailwind4 needs no JS config and nopostcss.config.js..gitignoreno longer carries the!tailwind.config.jsexception.src/app.cssreplaces the@tailwind base/components/utilitiesdirectives and carries over the two settings the old config file held:updatePluginDependenciesstill adds@nativescript/tailwindandtailwindcssto the rootdevDependencies; only its comment changed. Intools/update-versions.ts, both packages stay on theholdpolicy, 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, soholdonly freezes the floor.Why it looks like this
@nativescript/tailwindREADME says: "Import Tailwind: Add the following to yourapp.cssorapp.scss:@import 'tailwindcss';" and "Manual PostCSS configuration is typically not required for Tailwind CSS v4.@nativescript/tailwindhandles the necessary setup automatically." Itsnativescript.webpack.jsaddspostcss-preset-env,@tailwindcss/postcss,@nativescript/tailwindand@csstools/postcss-is-pseudo-classto thecss/scsspostcss-loaderrules throughchainWebpack.@nativescript/webpack5 applies it automatically because the apppackage.jsonlists@nativescript/tailwind.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 meanstheme.cssandutilities.csswithoutpreflight.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 }andbutton, 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 useddarkMode: ['class', '.ns-dark']. Tailwind's dark mode docs: "If you want your dark theme to be driven by a CSS selector instead of theprefers-color-schememedia query, override thedarkvariant to use your custom selector:@custom-variant dark (&:where(.dark, .dark *));".@nativescript/tailwind4.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.contentglobs. Tailwind 4 detects sources automatically from the build's working directory (the app root underns/webpack) and respects.gitignore. That replaces the v3content: ['./src/**/*.{css,xml,html,vue,svelte,ts,tsx}']. The e2e run below shows classes from.xmland Angular.htmltemplates being picked up.@nativescript/tailwind4.1.0 depends on@tailwindcss/postcss ^4.0.0, has a peer dependency onpostcss ^8, and is built against@nativescript/webpack ^5.0.8. Its 4.1.0 release notes describe it as "Tailwind v4 parity with@nativescript/core9.x". The generators already install@nativescript/core ~9.1.0and@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.csswith@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')inapplication.spec.ts. It asserts the 4.x versions, the apppackage.jsondevDependency, the newapp.cssimports (and that the fulltailwindcss/preflight.cssentry is absent), the.ns-darkcustom variant, no@tailwinddirectives, notailwind.config.jsand no.gitignoreexception. Without the change, it fails onexpected '~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: passesnpx prettier --checkon the changed files: cleanEnd-to-end verification
I packed the plugin (
npm packofdist/packages/nx) and installed it into a fresh, non-TS-solution Nx 24.0.7 workspace (TypeScript 6.0.3). npm resolvedtailwindcss4.3.5,@tailwindcss/postcss4.3.5,@nativescript/tailwind4.1.0 and@nativescript/webpack5.0.42.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.mjsandapps/nativescript-ngapp/platforms/android/app/src/main/assets/app/bundle.mjs.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-centerand.text-red-500. The angular sheet also has a*, ::before, ::after, ::backdroprule that only declares--tw-*custom properties (Tailwind 4's@propertyfallback) and sets no layout properties.Angular under TypeScript 6 defaults
The first Angular run hit TypeScript 6's
strictdefault in template files from #90. That is fixed on #90 (d4a460f), which is merged into this branch. Re-run with nostrictkey in the workspacetsconfig.base.json:nativescript-ngapp:preparesucceeds on iOS and Android, and both bundles contain.text-red-500 { color: var(--color-red-500) }.