-
-
Notifications
You must be signed in to change notification settings - Fork 319
fix(vite-plugin-angular): remove duplicate hmr option #2204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
cb34426
fix(nx-plugin): order analog before tailwind plugin
benpsnyder ae795e6
fix(create-analog): order analog before tailwind plugin
benpsnyder 8fb2979
docs(vite-plugin-angular): align tailwind guidance with generated setup
benpsnyder 18799fc
docs: add PR review and description agent skills
brandonroberts 74617db
docs: add test coverage and build artifact checks to review-pr skill
brandonroberts 95387db
feat(platform): add generic style-pipeline hooks for community plugin…
benpsnyder e0df473
chore: release 3.0.0-alpha.26 [skip ci]
semantic-release-bot 2537f41
refactor: retire root tsconfig paths and move workspace linking to pa…
benpsnyder 20acf90
Merge branch 'alpha' into fix/tailwind-csr
benpsnyder 7a29bbc
fix: reorder plugins in generator configuration for improved compatib…
benpsnyder 874419d
docs: clarify Angular HMR requirements and compatibility for versions…
benpsnyder 4a7ec54
docs: update link format for HMR migration guidance in Tailwind integ…
benpsnyder e0b4fba
test: add coverage for analog registration in vite.config.ts templates
benpsnyder 3326eca
Merge remote-tracking branch 'origin/alpha' into fix/tailwind-csr
benpsnyder 94c2f5b
refactor: update Angular live-reload configuration and Tailwind integ…
benpsnyder 75ffacd
refactor: remove hmr compatibility alias and streamline live-reload c…
benpsnyder 87af10d
Merge branch 'alpha' into fix/tailwind-csr
brandonroberts 792e785
chore: update tsconfig path in live reload test
brandonroberts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| # Tailwind CSS v4 | ||
|
|
||
| Analog supports Tailwind CSS v4 for both: | ||
|
|
||
| - utility classes in templates | ||
| - `@apply` inside Angular component styles | ||
|
|
||
| The supported v3 `alpha` setup is: | ||
|
|
||
| 1. keep one root stylesheet such as `src/styles.css` | ||
| 2. put `@import 'tailwindcss';` in that stylesheet | ||
| 3. enable `@tailwindcss/vite` in `vite.config.ts` | ||
| 4. keep a `postcss.config.mjs` with `@tailwindcss/postcss` | ||
| 5. configure Analog with `tailwindCss.rootStylesheet` | ||
|
|
||
| Generated apps already follow this shape. | ||
|
|
||
| ## Install | ||
|
|
||
| ```sh | ||
| npm install -D tailwindcss @tailwindcss/vite @tailwindcss/postcss postcss | ||
| ``` | ||
|
|
||
| ## Vite Config | ||
|
|
||
| ```ts | ||
| /// <reference types="vitest" /> | ||
|
|
||
| import { resolve } from 'node:path'; | ||
| import { defineConfig } from 'vite'; | ||
| import analog from '@analogjs/platform'; | ||
| import tailwindcss from '@tailwindcss/vite'; | ||
|
|
||
| export default defineConfig(() => ({ | ||
| plugins: [ | ||
| analog({ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should flow through the analog plugin to the Vite plugin. |
||
| vite: { | ||
| tailwindCss: { | ||
| rootStylesheet: resolve(__dirname, 'src/styles.css'), | ||
| }, | ||
| }, | ||
| }), | ||
| tailwindcss(), | ||
| ], | ||
| })); | ||
| ``` | ||
|
|
||
| Use an absolute `rootStylesheet` path. Analog may serve component styles through virtual stylesheet ids during dev, so relative `@reference` paths are not reliable there. | ||
|
|
||
| If you are using `@analogjs/vite-plugin-angular` directly instead of `@analogjs/platform`, the same Tailwind option lives on the Angular plugin itself: | ||
|
|
||
| ```ts | ||
| import { resolve } from 'node:path'; | ||
| import { defineConfig } from 'vite'; | ||
| import angular from '@analogjs/vite-plugin-angular'; | ||
| import tailwindcss from '@tailwindcss/vite'; | ||
|
|
||
| export default defineConfig(() => ({ | ||
| plugins: [ | ||
| angular({ | ||
| tailwindCss: { | ||
| rootStylesheet: resolve(__dirname, 'src/styles.css'), | ||
| }, | ||
| }), | ||
| tailwindcss(), | ||
| ], | ||
| })); | ||
| ``` | ||
|
|
||
| ## Root Stylesheet | ||
|
|
||
| In `src/styles.css`: | ||
|
|
||
| ```css | ||
| @import 'tailwindcss'; | ||
| ``` | ||
|
|
||
| You can keep your theme, `@source`, plugins, and prefixes there as well: | ||
|
|
||
| ```css | ||
| @import 'tailwindcss' prefix(tw); | ||
|
|
||
| @source './src'; | ||
|
|
||
| @theme { | ||
| --color-primary: #3b82f6; | ||
| } | ||
| ``` | ||
|
|
||
| ## PostCSS Config | ||
|
|
||
| Create `postcss.config.mjs`: | ||
|
|
||
| ```js | ||
| export default { | ||
| plugins: { | ||
| '@tailwindcss/postcss': {}, | ||
| }, | ||
| }; | ||
| ``` | ||
|
|
||
| Keep this even if dev already works with `@tailwindcss/vite`. Current Analog builds still rely on the PostCSS path for production CSS processing. | ||
|
|
||
| ## How Component Styles Work | ||
|
|
||
| Angular compiles component styles in isolation. When a component stylesheet contains `@apply`, Tailwind still needs access to the root stylesheet that defines prefixes, theme values, and plugins. | ||
|
|
||
| Analog handles that by: | ||
|
|
||
| - detecting Tailwind usage in component CSS | ||
| - injecting the correct `@reference` to the configured root stylesheet | ||
| - externalizing component styles during dev when needed so they flow through Vite's CSS pipeline | ||
| - preserving the build path through PostCSS for production | ||
|
|
||
| That means you should not manually add `@reference` to every component stylesheet in the normal setup. | ||
|
|
||
| ## Plugin Order | ||
|
|
||
| List `analog()` before `tailwindcss()` in your Vite config. That is now how the generators scaffold it. | ||
|
|
||
| ```ts | ||
| plugins: [analog({ vite: { tailwindCss: { ... } } }), tailwindcss()]; | ||
| ``` | ||
|
|
||
| This keeps the config aligned with the generated apps and the current documentation. | ||
|
|
||
| ## HMR | ||
|
|
||
| Prefer `hmr` over `liveReload` when you need to configure Angular HMR explicitly. `liveReload` remains a compatibility alias. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| Angular HMR requires Angular v19 or newer. On Angular v16-v18, `hmr` and `liveReload` are intentionally disabled at runtime and emit a console warning, so HMR is unavailable on those versions. For the broader migration guidance, see [Enabling HMR](/docs/guides/migrating#enabling-hmr). | ||
|
|
||
| Tailwind support does not require you to enable HMR manually. The stylesheet pipeline is handled independently from whether Angular can produce a hot component update for a given edit. | ||
|
|
||
| ## Prefixes | ||
|
|
||
| If your component styles use custom-prefixed utilities, configure `prefixes` so Analog knows which stylesheets need Tailwind `@reference` injection: | ||
|
|
||
| ```ts | ||
| analog({ | ||
| vite: { | ||
| tailwindCss: { | ||
| rootStylesheet: resolve(__dirname, 'src/styles.css'), | ||
| prefixes: ['tw:'], | ||
| }, | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| Without `prefixes`, Analog falls back to its default Tailwind usage detection for component styles. | ||
|
|
||
| ## Generated Apps | ||
|
|
||
| Current `create-analog` and Nx app scaffolds both generate: | ||
|
|
||
| - `@import 'tailwindcss';` in `src/styles.css` | ||
| - `@tailwindcss/vite` in `vite.config.ts` | ||
| - `postcss.config.mjs` with `@tailwindcss/postcss` | ||
|
|
||
| If you start from a generated app, keep that structure unless you have a specific reason to diverge from the supported path. | ||
|
|
||
| ## Related | ||
|
|
||
| - [Using CSS Pre-processors](/docs/packages/vite-plugin-angular/css-preprocessors) | ||
| - [create-analog](/docs/packages/create-analog/overview) | ||
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having both the Vite plugin and postcss feels like a bad solution. The Tailwind docs mention them as an either/or with the Vite plugin being the primary option.