Skip to content

Commit 94c2f5b

Browse files
committed
refactor: update Angular live-reload configuration and Tailwind integration
1 parent 3326eca commit 94c2f5b

15 files changed

Lines changed: 119 additions & 131 deletions

File tree

apps/docs-app/docs/guides/migrating-v2-to-v3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,4 @@ Keep automated migration tooling focused on the breaking changes above:
158158
- rewrite only the legacy `@analogjs/vite-plugin-angular/setup-vitest` setup import
159159
- flag `@analogjs/trpc` as a removed package that needs a manual migration plan
160160
- flag `experimental.useAnalogCompiler`, `analogCompilationMode`, and `@analogjs/angular-compiler` as unsupported on the current v3 alpha line rather than removed outright
161-
- treat optional helpers such as `withTypedRouter`, `withRouteContext`, `withLoaderCaching`, `withDebugRoutes`, and compatibility aliases such as `liveReload` as opt-in rather than mandatory rewrites
161+
- treat optional helpers such as `withTypedRouter`, `withRouteContext`, `withLoaderCaching`, `withDebugRoutes`, and compatibility aliases such as `hmr` as opt-in rather than mandatory rewrites

apps/docs-app/docs/guides/migrating.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,11 @@ export default defineConfig(({ mode }) => ({
190190

191191
## Enabling HMR
192192

193-
Angular supports HMR where in most cases components can be updated without a full page reload. In Analog, prefer the `hmr` option. `liveReload` is still accepted as a compatibility alias, but `hmr` is the primary API.
194-
Analog requires Angular v19 or newer for `hmr` / `liveReload` to work. On Angular v17-v18, `hmr` and its `liveReload` alias are forcibly disabled at runtime with a console warning, so HMR is unavailable on those versions.
193+
Angular supports HMR where in most cases components can be updated without a full page reload. In Analog, use `liveReload` to control the Angular live-reload pipeline.
194+
195+
This is separate from Vite's `server.hmr` option, which configures the HMR websocket transport. You can use `server.hmr` together with `liveReload` when you need custom host, port, or path settings. `hmr` is still accepted as a compatibility alias for `liveReload`.
196+
197+
Analog requires Angular v19 or newer for `liveReload` / `hmr` to work. On Angular v17-v18, `liveReload` and its `hmr` alias are forcibly disabled at runtime with a console warning, so HMR is unavailable on those versions.
195198

196199
```ts
197200
/// <reference types="vitest" />
@@ -204,7 +207,7 @@ export default defineConfig(({ mode }) => ({
204207
// .. other configuration
205208
plugins: [
206209
analog({
207-
hmr: true,
210+
liveReload: true,
208211
}),
209212
],
210213
}));
@@ -223,7 +226,7 @@ import tailwindcss from '@tailwindcss/vite';
223226
export default defineConfig(() => ({
224227
plugins: [
225228
analog({
226-
hmr: true,
229+
liveReload: true,
227230
vite: {
228231
tailwindCss: {
229232
rootStylesheet: resolve(import.meta.dirname, 'src/styles.css'),

apps/docs-app/docs/integrations/storybook/index.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ const config: StorybookConfig = {
9191
export default config;
9292
```
9393

94-
For current Analog projects, prefer `framework.options.hmr` if you need to configure Angular HMR. `liveReload` is still accepted as a compatibility alias, but `hmr` is the recommended option.
94+
For current Analog projects, use `framework.options.liveReload` to control Analog's Angular live-reload behavior.
95+
96+
This is separate from Vite's `server.hmr` option, which configures the HMR websocket transport. You can use `server.hmr` together with `framework.options.liveReload` when Storybook needs custom host, port, or path settings. `framework.options.hmr` is still accepted as a compatibility alias.
9597

9698
Remove the existing `webpackFinal` config function if present.
9799

@@ -148,7 +150,7 @@ If your project uses Tailwind v4, keep Storybook aligned with the same opinionat
148150
- one root stylesheet such as `src/styles.css`
149151
- `@import 'tailwindcss';` in that stylesheet
150152
- `framework.options.tailwindCss.rootStylesheet` pointing at that stylesheet
151-
- `framework.options.hmr` for Angular HMR behavior
153+
- `framework.options.liveReload` for Angular reload behavior
152154

153155
```ts
154156
import { resolve } from 'node:path';
@@ -158,7 +160,7 @@ const config: StorybookConfig = {
158160
framework: {
159161
name: '@analogjs/storybook-angular',
160162
options: {
161-
hmr: true,
163+
liveReload: true,
162164
tailwindCss: {
163165
rootStylesheet: resolve(__dirname, '../src/styles.css'),
164166
},

apps/docs-app/docs/integrations/tailwind/index.md

Lines changed: 38 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
# Tailwind CSS v4
22

3-
Analog supports Tailwind CSS v4 for both:
3+
Analog does not replace Tailwind's installation guides. Start with one Tailwind setup that matches your project:
44

5-
- utility classes in templates
6-
- `@apply` inside Angular component styles
5+
- [Install Tailwind with Vite](https://tailwindcss.com/docs/installation/using-vite)
6+
- [Install Tailwind with PostCSS](https://tailwindcss.com/docs/installation/using-postcss)
7+
- [Install Tailwind with Angular](https://tailwindcss.com/docs/installation/framework-guides/angular)
78

8-
The supported v3 `alpha` setup is:
9+
Once Tailwind is installed, Analog adds the Angular-specific part: component stylesheet handling for `@apply` and Tailwind-aware `@reference` injection.
910

10-
1. keep one root stylesheet such as `src/styles.css`
11-
2. put `@import 'tailwindcss';` in that stylesheet
12-
3. enable `@tailwindcss/vite` in `vite.config.ts`
13-
4. keep a `postcss.config.mjs` with `@tailwindcss/postcss`
14-
5. configure Analog with `tailwindCss.rootStylesheet`
11+
## What Analog adds
1512

16-
Generated apps already follow this shape.
13+
Use Analog's `tailwindCss.rootStylesheet` option when you want Tailwind utilities inside Angular component styles.
1714

18-
## Install
15+
That option lets Analog:
1916

20-
```sh
21-
npm install -D tailwindcss @tailwindcss/vite @tailwindcss/postcss postcss
22-
```
17+
- detect component stylesheets that use Tailwind utilities
18+
- inject the correct `@reference` to your root stylesheet
19+
- keep component styles aligned with your root Tailwind theme, prefixes, and plugins
20+
- avoid manual `@reference` directives in every component stylesheet
21+
22+
If you only use Tailwind utilities in templates and a global stylesheet, you can follow Tailwind's install docs and keep your generated scaffold defaults without adding extra Analog configuration.
2323

24-
## Vite Config
24+
## Component Styles Setup
25+
26+
When you enable `tailwindCss.rootStylesheet`, keep Tailwind wired through Vite for the component stylesheet path:
2527

2628
```ts
2729
/// <reference types="vitest" />
@@ -45,9 +47,7 @@ export default defineConfig(() => ({
4547
}));
4648
```
4749

48-
Use an absolute `rootStylesheet` path. Analog may serve component styles through virtual stylesheet ids during dev, so relative `@reference` paths are not reliable there.
49-
50-
If you are using `@analogjs/vite-plugin-angular` directly instead of `@analogjs/platform`, the same Tailwind option lives on the Angular plugin itself:
50+
If you are using `@analogjs/vite-plugin-angular` directly instead of `@analogjs/platform`, the same option lives on the Angular plugin:
5151

5252
```ts
5353
import { resolve } from 'node:path';
@@ -67,6 +67,8 @@ export default defineConfig(() => ({
6767
}));
6868
```
6969

70+
List `analog()` before `tailwindcss()` in your Vite config. Current generators now scaffold that order.
71+
7072
## Root Stylesheet
7173

7274
In `src/styles.css`:
@@ -87,19 +89,7 @@ You can keep your theme, `@source`, plugins, and prefixes there as well:
8789
}
8890
```
8991

90-
## PostCSS Config
91-
92-
Create `postcss.config.mjs`:
93-
94-
```js
95-
export default {
96-
plugins: {
97-
'@tailwindcss/postcss': {},
98-
},
99-
};
100-
```
101-
102-
Keep this even if dev already works with `@tailwindcss/vite`. Current Analog builds still rely on the PostCSS path for production CSS processing.
92+
Use an absolute `rootStylesheet` path. Analog may serve component styles through virtual stylesheet ids during dev, so relative `@reference` paths are not reliable there.
10393

10494
## How Component Styles Work
10595

@@ -108,30 +98,11 @@ Angular compiles component styles in isolation. When a component stylesheet cont
10898
Analog handles that by:
10999

110100
- detecting Tailwind usage in component CSS
111-
- injecting the correct `@reference` to the configured root stylesheet
112-
- externalizing component styles during dev when needed so they flow through Vite's CSS pipeline
113-
- preserving the build path through PostCSS for production
101+
- injecting `@reference` to the configured root stylesheet
102+
- routing those component styles through the Vite CSS pipeline when needed
114103

115104
That means you should not manually add `@reference` to every component stylesheet in the normal setup.
116105

117-
## Plugin Order
118-
119-
List `analog()` before `tailwindcss()` in your Vite config. That is now how the generators scaffold it.
120-
121-
```ts
122-
plugins: [analog({ vite: { tailwindCss: { ... } } }), tailwindcss()];
123-
```
124-
125-
This keeps the config aligned with the generated apps and the current documentation.
126-
127-
## HMR
128-
129-
Prefer `hmr` over `liveReload` when you need to configure Angular HMR explicitly. `liveReload` remains a compatibility alias.
130-
131-
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).
132-
133-
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.
134-
135106
## Prefixes
136107

137108
If your component styles use custom-prefixed utilities, configure `prefixes` so Analog knows which stylesheets need Tailwind `@reference` injection:
@@ -149,15 +120,25 @@ analog({
149120

150121
Without `prefixes`, Analog falls back to its default Tailwind usage detection for component styles.
151122

123+
## HMR
124+
125+
Use `liveReload` when you need to configure Analog's Angular live-reload behavior explicitly.
126+
127+
Vite's `server.hmr` option is separate. It controls the HMR websocket transport, so you can use `server.hmr` together with `liveReload` when your dev server needs custom host, port, or path settings. `hmr` is still accepted as a compatibility alias for `liveReload`.
128+
129+
Angular HMR requires Angular v19 or newer. On Angular v17-v18, `liveReload` and its `hmr` alias are intentionally disabled at runtime and emit a console warning, so HMR is unavailable on those versions. For broader migration guidance, see the [migration guide](/docs/guides/migrating).
130+
131+
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.
132+
152133
## Generated Apps
153134

154-
Current `create-analog` and Nx app scaffolds both generate:
135+
Current `create-analog` and Nx app scaffolds already:
155136

156-
- `@import 'tailwindcss';` in `src/styles.css`
157-
- `@tailwindcss/vite` in `vite.config.ts`
158-
- `postcss.config.mjs` with `@tailwindcss/postcss`
137+
- import Tailwind in `src/styles.css`
138+
- register Tailwind in `vite.config.ts`
139+
- keep the generated Vite plugin order aligned with the current Analog templates
159140

160-
If you start from a generated app, keep that structure unless you have a specific reason to diverge from the supported path.
141+
Some templates may also include additional Tailwind tooling config files. Treat the generated scaffold as your project default, and only diverge after validating your own dev and build behavior.
161142

162143
## Related
163144

apps/docs-app/docs/packages/create-analog/overview.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,11 @@ pnpm create analog
4747

4848
### Tailwind v4
4949

50-
`create-analog` scaffolds Tailwind v4 with the current supported Analog setup. Generated projects include:
50+
`create-analog` scaffolds Tailwind v4 for the current Analog templates. Generated projects import Tailwind in `src/styles.css` and wire the Tailwind-related Vite config the template expects.
5151

52-
- one root stylesheet, usually `src/styles.css`, with `@import 'tailwindcss';`
53-
- `@tailwindcss/vite` in `vite.config.ts`
54-
- `postcss.config.mjs` with `@tailwindcss/postcss`
52+
If you only need Tailwind utilities in templates and global styles, keep the scaffold defaults.
5553

56-
Analog then handles component-level `@reference` injection through its Tailwind-aware stylesheet pipeline, so you do not need to add `@reference` directives manually to every component stylesheet.
57-
58-
For the full Tailwind v4 setup and behavior details, see the [Tailwind CSS integration guide](/docs/integrations/tailwind).
54+
If you also want `@apply` inside Angular component styles, add Analog's `tailwindCss.rootStylesheet` option and follow the [Tailwind CSS guide](/docs/integrations/tailwind).
5955

6056
If you do not want Tailwind in the generated app, pass `--skipTailwind true`. The default Tailwind v4 flow expects a plain CSS entry file for global styles.
6157

apps/docs-app/docs/packages/vite-plugin-angular/css-preprocessors.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ title: 'Using CSS Pre-processors'
44

55
The Vite Plugin supports CSS pre-processing using external `styleUrls` and inline `styles` in the Component decorator metadata.
66

7-
## Recommended Tailwind v4 setup
7+
## Tailwind v4 component styles
88

9-
If your app uses Tailwind v4, keep the supported Analog setup:
9+
Tailwind installation itself should follow Tailwind's docs. The Analog-specific configuration below is for Angular component styles that use Tailwind utilities such as `@apply`.
1010

1111
- keep a single root stylesheet such as `src/styles.css`
1212
- put `@import 'tailwindcss';` in that root stylesheet
1313
- keep `@tailwindcss/vite` enabled in `vite.config.ts`
14-
- keep `postcss.config.mjs` with `@tailwindcss/postcss`
1514
- configure Analog with `tailwindCss.rootStylesheet`
1615

1716
This lets Analog preprocess component stylesheets and inject the correct `@reference` directive automatically for component CSS that uses Tailwind utilities.
1817

19-
For the complete setup and Tailwind-specific guidance, see the [Tailwind CSS integration guide](/docs/integrations/tailwind).
18+
For the broader Tailwind + Analog overview, see the [Tailwind CSS guide](/docs/integrations/tailwind).
2019

2120
```ts
2221
/// <reference types="vitest" />
@@ -32,7 +31,7 @@ export default defineConfig(() => ({
3231
tailwindCss: {
3332
rootStylesheet: resolve(__dirname, 'src/styles.css'),
3433
},
35-
hmr: true,
34+
liveReload: true,
3635
}),
3736
tailwindcss(),
3837
],
@@ -45,20 +44,14 @@ And in `src/styles.css`:
4544
@import 'tailwindcss';
4645
```
4746

48-
And in `postcss.config.mjs`:
49-
50-
```js
51-
export default {
52-
plugins: {
53-
'@tailwindcss/postcss': {},
54-
},
55-
};
56-
```
57-
5847
Use an absolute path for `rootStylesheet`. Analog serves some component styles through virtual stylesheet ids during dev, so relative `@reference` paths are not reliable there.
5948

49+
Use `liveReload` to control Analog's Angular reload behavior. Vite's top-level `server.hmr` option remains available when you need to configure the HMR websocket transport separately.
50+
6051
You only need `tailwindCss.prefixes` when your component styles use custom-prefixed utilities and you want Analog to look for those prefixes instead of the default `@apply` detection.
6152

53+
If you only use Tailwind utilities in templates and a global stylesheet, you can keep your Tailwind install path and skip `tailwindCss.rootStylesheet`.
54+
6255
External `styleUrls` can be used without any additional configuration.
6356

6457
An example with `styleUrls`:

packages/platform/src/lib/options.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export interface Options {
9898
*
9999
* When `false`, the following top-level options are ignored because they
100100
* are only forwarded to the internal Angular plugin: `jit`,
101-
* `disableTypeChecking`, `hmr`, `liveReload`, `inlineStylesExtension`,
101+
* `disableTypeChecking`, `liveReload`, `hmr`, `inlineStylesExtension`,
102102
* `fileReplacements`, and `include`.
103103
*
104104
* Use this to configure the embedded Angular integration itself, not as the
@@ -116,15 +116,18 @@ export interface Options {
116116
*/
117117
inlineStylesExtension?: string;
118118
/**
119-
* Enables Angular's HMR during development/watch mode.
119+
* Enables Analog's Angular live-reload/HMR pipeline during development/watch mode.
120+
*
121+
* This is separate from Vite's `server.hmr` option, which configures the
122+
* HMR client transport.
120123
*
121124
* Defaults to `true` for watch mode.
122125
*/
123-
hmr?: boolean;
126+
liveReload?: boolean;
124127
/**
125-
* @deprecated Use `hmr` instead. Kept as a compatibility alias.
128+
* Compatibility alias for `liveReload`.
126129
*/
127-
liveReload?: boolean;
130+
hmr?: boolean;
128131
/**
129132
* Enable debug logging for specific scopes.
130133
*

packages/storybook-angular/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const config: StorybookConfig = {
3535
framework: {
3636
name: '@analogjs/storybook-angular',
3737
options: {
38-
hmr: true,
38+
liveReload: true,
3939
},
4040
},
4141
};
@@ -123,7 +123,9 @@ In your global stylesheet, import Tailwind with:
123123

124124
Storybook does not automatically infer the Tailwind plugin from your app's `vite.config.ts`, so add it in `viteFinal` when your stories depend on Tailwind utilities.
125125

126-
Angular HMR is controlled with `framework.options.hmr`. `liveReload` is still accepted as a compatibility alias, but `hmr` is the preferred option.
126+
Angular reload behavior is controlled with `framework.options.liveReload`.
127+
128+
This is separate from Vite's `server.hmr` option, which configures the HMR websocket transport. You can use `server.hmr` together with `framework.options.liveReload` when Storybook needs custom host, port, or path settings. `framework.options.hmr` is still accepted as a compatibility alias.
127129

128130
## Enabling Zoneless Change Detection
129131

packages/storybook-angular/src/lib/preset.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,28 +132,28 @@ describe('viteFinal', () => {
132132
};
133133

134134
describe('Angular plugin options', () => {
135-
it('prefers hmr over liveReload and keeps liveReload as compatibility input', async () => {
136-
const options = makeOptions({ hmr: true, liveReload: false });
135+
it('prefers liveReload over hmr and keeps hmr as compatibility input', async () => {
136+
const options = makeOptions({ liveReload: false, hmr: true });
137137

138138
await viteFinal(baseConfig, options);
139139

140140
expect(angularPluginMock).toHaveBeenCalledWith(
141141
expect.objectContaining({
142-
hmr: true,
143142
liveReload: false,
143+
hmr: false,
144144
}),
145145
);
146146
});
147147

148-
it('falls back to liveReload when hmr is omitted', async () => {
149-
const options = makeOptions({ liveReload: true });
148+
it('falls back to hmr when liveReload is omitted', async () => {
149+
const options = makeOptions({ hmr: true });
150150

151151
await viteFinal(baseConfig, options);
152152

153153
expect(angularPluginMock).toHaveBeenCalledWith(
154154
expect.objectContaining({
155-
hmr: true,
156155
liveReload: true,
156+
hmr: true,
157157
}),
158158
);
159159
});

0 commit comments

Comments
 (0)