Skip to content

Commit 8992050

Browse files
committed
fix: update Tailwind CSS integration and add production configuration details
1 parent a5a0481 commit 8992050

8 files changed

Lines changed: 1283 additions & 41 deletions

File tree

apps/docs-app/docs/integrations/angular-material/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ export default defineConfig({
164164
@import 'tailwindcss';
165165
```
166166

167-
> **Note:** Analog's default Tailwind v4 setup uses `@tailwindcss/vite`. You do not need a `.postcssrc.json` file or a generated `tailwind.config.*` file for the standard Vite-based setup.
167+
> **Note:** Analog's default Tailwind v4 setup uses `@tailwindcss/vite` for development. You do not need a generated `tailwind.config.*` file for the standard Vite-based setup.
168+
>
169+
> **For production builds** that use `@apply` in component stylesheets (`.component.css`), you also need `@tailwindcss/postcss` configured in a `postcss.config.mjs`. See the [Tailwind CSS integration guide](/docs/integrations/tailwind) for full details.
168170
>
169171
> The scaffolded Tailwind v4 flow also expects a plain CSS entry file such as `src/styles.css`. If your app currently uses Sass or Less for the global entry point, keep your existing setup or migrate that entry file to CSS before adopting the default Tailwind v4 flow.
170172

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

Lines changed: 538 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ pnpm create analog
4747

4848
### Tailwind v4
4949

50-
`create-analog` scaffolds Tailwind v4 with the Vite plugin by default for the current Analog templates. Generated projects use `@tailwindcss/vite`, add `@import 'tailwindcss';` to `src/styles.css`, and do not create a `.postcssrc.json` file or a `tailwind.config.*` file for the standard setup.
50+
`create-analog` scaffolds Tailwind v4 with the Vite plugin by default for the current Analog templates. Generated projects use `@tailwindcss/vite`, add `@import 'tailwindcss';` to `src/styles.css`, and do not create a `tailwind.config.*` file for the standard setup.
51+
52+
**For production builds** that use `@apply` in component stylesheets (`.component.css`), you should also install `@tailwindcss/postcss` and create a `postcss.config.mjs`. Without it, `@apply` directives in component styles will not be resolved during `vite build`. See the [Tailwind CSS integration guide](/docs/integrations/tailwind) for full configuration details.
5153

5254
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.
5355

packages/platform/src/lib/options.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ export interface Options {
8888
*/
8989
liveReload?: boolean;
9090

91+
/**
92+
* Enable verbose debug logging for Tailwind CSS integration, HMR, and
93+
* component style processing. Logs are prefixed with `[analog:debug]`.
94+
*/
95+
debugTailwindCss?: boolean;
96+
9197
/**
9298
* Additional page paths to include
9399
*/

packages/platform/src/lib/platform-plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export function platformPlugin(opts: Options = {}): Plugin[] {
7979
liveReload: platformOptions.liveReload,
8080
inlineStylesExtension: platformOptions.inlineStylesExtension,
8181
fileReplacements: platformOptions.fileReplacements,
82+
debugTailwindCss: platformOptions.debugTailwindCss,
8283
...(viteOptions ?? {}),
8384
experimental: {
8485
...(viteOptions?.experimental ?? {}),

packages/vite-plugin-angular/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,9 @@ Create a `tsconfig.app.json` in the root of the project.
8989
"include": ["src/**/*.ts"]
9090
}
9191
```
92+
93+
## Tailwind CSS v4
94+
95+
The plugin provides first-class Tailwind CSS v4 support for Angular component styles, including `@apply` in `.component.css` files, DaisyUI, and custom prefixes.
96+
97+
See the [Tailwind CSS integration guide](/docs/integrations/tailwind) for full setup instructions covering CSR, SSR, SSG, library builds, Vitest, DaisyUI, and production configuration.

packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts

Lines changed: 699 additions & 36 deletions
Large diffs are not rendered by default.

packages/vite-plugin-angular/src/lib/host.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,36 @@ export function augmentHostWithResources(
8686
console.error(`${e}`);
8787
}
8888

89-
return { content: stylesheetResult?.code || '' };
89+
// Return null when the transform fails entirely, allowing Angular to
90+
// surface the error rather than silently replacing the stylesheet with
91+
// empty content. An empty string would cause Angular to proceed as if
92+
// the component had no styles — hiding preprocessing errors.
93+
if (stylesheetResult?.code == null) {
94+
return null;
95+
}
96+
97+
return { content: stylesheetResult.code };
9098
};
9199

100+
/**
101+
* Maps a resource name (template or stylesheet URL from a component
102+
* decorator) to a file path on disk.
103+
*
104+
* For stylesheets when externalComponentStyles is active, creates a
105+
* hash-based virtual ID and stores the mapping so that resolveId/load
106+
* can serve these through Vite's pipeline.
107+
*
108+
* @param resourceName - The URL from the component decorator (e.g. './foo.component.css')
109+
* @param containingFile - Absolute path to the .ts file that references the resource
110+
* @param fallbackResolve - Optional callback from Angular's resource loader that
111+
* uses TypeScript's module resolution as a fallback. Accepted for API
112+
* compatibility but intentionally not called for stylesheets (Analog's
113+
* hash-based approach is authoritative).
114+
*/
92115
resourceHost.resourceNameToFileName = function (
93-
resourceName,
94-
containingFile,
116+
resourceName: string,
117+
containingFile: string,
118+
fallbackResolve?: (url: string, fromFile: string) => string | null,
95119
) {
96120
const resolvedPath = path.join(path.dirname(containingFile), resourceName);
97121

0 commit comments

Comments
 (0)