webpack / webpack/postcss-loader

Angular+Tailwind: New classes are not added when symlink is present

Open
#623 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
2.8k
Forks
211
Avg merge
51m
Merged PRs (30d)
1

Description

Preamble

Yes, this bug report is very unspecific to webpack and I cannot say what is wrong where, because I don't have the knowledge, but the tailwind developer said the bug could be in webpack and the angular developer said the problem seems to rely in webpack.

My previous issues leading me to webpack:
https://github.com/tailwindlabs/tailwindcss/issues/10555
https://github.com/angular/angular-cli/issues/24705

Information from @thecrypticace (tailwind developer)

  1. On the initial build we are returning the expected content paths from our plugin for postcss-loader to hand off to webpack.
  2. On subsequent builds Tailwind CSS itself isn't called at all by Angular (I'm guessing PostCSS itself isn't called)
  3. This problem is only present when a glob path is passed to postcss-loader AND there is a symlink inside the "root" (non-dynamic) directory of the glob path.
  4. I suspected this was a problem with the persistent cache but disabling the angular cache does not fix this.

He said that he is willing to provide additional information if needed.

Information from @alan-agius4 (angular developer)

This seems to be an issue with Webpack itself.
I can see that the correct dependencies are added by postcss/tailwinds in webpack-contrib/postcss-loader@888d72e/src/index.js#L196-L198. But, for some reason when the added ContextDependency is a directory with a nested symlink, Webpack do not invalidate the correct files.

Bug report

New tailwind classes are not added in ng serve without restarting it, while a symlink exists in tailwinds content path.
This issue can be fixed by removing the symlink. Now class changes are added without restarting ng serve.
It does not matter what file type it is, the existence of a symlink is enough to break it.

Actual Behavior

Changes in files are not reflected in watched output.

Expected Behavior

The dependency should be invalidated and recompiled.

How Do We Reproduce?

setup new angular project:

ng new --minimal --style scss --defaults tailwind-symlink-bug
cd tailwind-symlink-bug/
npm install --save-dev tailwindcss
ln -s ../../node_modules/@angular/core/README.md src/assets/README.md
echo "module.exports = { content: ['./src/**/*.{html,ts}'] };" > tailwind.config.js
echo -e "@tailwind base;\n@tailwind components;\n@tailwind utilities;" > src/styles.scss

replace html in app.component.ts with following:

<div class="w-40 h-40 bg-red-500"></div>

start:

ng serve

You will see a red square. Now change bg-red-500 to bg-green-500 -> the square will disappear, as the new tailwind class is not generated. A restart of ng serve will add it.

If you remove the symlink at src/assets/README.md and restart ng serve, the problem above does not appear.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the Angular project and symlink commands in the report, then inspect postcss-loader/src/index.js around lines 196-198 and webpack's handling of the added ContextDependency. Confirm that changing the Tailwind class under ng serve invalidates and recompiles the watched output without restarting.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, javascript, tailwindcss, webpack
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.