You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow exclusion of files / folders from being watched by @angular-devkit/build-angular:application (ESBuild + Vite) #26644
Webpack previously allowed a customWebpackConfig and therefore it was possible to exclude certain files and folders from the "watch" mechanism. With Vite this option is completely gone. In bigger setups with lots of libraries and Cypress/Jest tests residing in the folder of each library, the app gets rebuilt every time an irrelevant file (i.e. my-test.e2e.spec.ts, my-test.spec.ts or my-test.cy.ts) was changed.
Especially creating and editing Cypress tests becomes a real an absolute struggle because you have to wait for the build to be completed before you can run a test properly.
The watching is indeed not done by Vite, but this is done as part of the application builder implementation, a rebuild only happens when a file that is referenced in the application is modified.
To give you a clearer view:
We have 170+ buildable libraries and each library has a folder "src" with the actual code and a folder "cypress" which contains e2e-tests, pageobjects, and so on. Then we have Jest- and Cypress-Component-Tests that are within the "src" folder, right besides each specific component or util.
Everytime I change a pageobject, e2e-test, jest-test or one of the Cypress-tests generates an output within that library (i.e. "my-lib/reports"), a rebuild was triggered with webpack (and also with vite).
In the past, we didn't offer support for excluding files from the watcher, and it's not a feature we intend to introduce. However, it does seems there might be a bug in ng-packagr causing a library rebuild when a non-compilation file like my-lib/reports is modified, resulting in an unnecessary application build.
I see that spec-Files and totally unrelated files show up here. Using --verbose on the serve command I also see that unrelated HTML-files trigger a rebuild (they were stored within a libs-folder there other Angular libs reside).
But then it gets blurry. I see the reference to the evn variable NG_BUILD_WATCH_ROOT, but I didn't set this variable.
From the side of ESBuild I didn't find out anything.. I see that you can give ESBuild entrypoints, but that's it. I don't see how other files are included in the watched files..
and then tsconfig.spec.json and cypress/tsconfig.json include Jest- and Cypress-Tests but have different settings for the types, (for cypress/tsconfig.json -> "types": ["cypress", "node", "cypress-axe"],).
When I running nx/ng serve it seems that only the main "tsconfig.app.json" is respected anyways (I saw this because in one library there was a problem with an import using require, so I switched it to CommonJS (because there seem to be no alternatives for https://github.com/nx-js/compiler-util -> I fixed it with import { compileCode, expose } from '@nx-js/compiler-util/dist/cjs.es6.js';). When doing a build, it would respect the tsconfig.json of that very library and when running serve it would respect tsconfig.app.json. I had to add esModuleInterop to both configs.
So I don't understand how the TSConfigs would affect the file watcher and how I could check how it is affecting the watcher.
But thanks to your hints I found the culprit: The Tailwind configuration.
It not documented very well on their website and according to some older issues, it seems that exclusions are not possible:
But NX, with its default setup, generates globPatterns that have some sort of exclusion: **/!(*.stories|*.spec).{ts,html}
Not I can extend this glob pattern and possibly create an MR for NX to extend these exclusions per default (to also match cypress.config.ts, my-util.test.ts, my-other-test.cy.ts).
As for now I'll ignore my huge ignore list for webpack and go on with the fixed Tailwind content globs and observe how the new watcher behaves with other files (as you see code-coverage output generated by Cypress was also a problem).
Last problem to solve now is using @media screens(xs) {..} or the old @screens xs {..} in SCSS-files with angular plugin-sass:
Previously we used @screen which still is supported (but not documented anymore) and it works just fine with the Webpack bundler. Maybe it works because of some very well hidden configuration in that setup.
In a new setup I tried it with Tailwind 3.0.2, 3.3.5 and 3.3.6 and none of these options work..
But still, it is very confusing because our setup works with Webpack and Tailwind (I don't know why it works) and it doesn't work with ESBuild. So something in the bundler must have changed too, since I didn't update Tailwind in my real project. Any ideas/hints other than to delete everything Tailwind-related and start from scratch? 😅
This should not work when when using SCSS with both webpack and esbuild based builder. This is because the Sass compiler runs before Tailwind and the latter is only invoked if the Sass compilation is successfully.
In this cases the error is correct, the fact that it worked, was likely a bug in the Sass compiler that was fixed.
Example of the error with Webpack when using Angular CLI version 17
Activity
alan-agius4 commentedon Dec 12, 2023
The watching is indeed not done by Vite, but this is done as part of the application builder implementation, a rebuild only happens when a file that is referenced in the application is modified.
Can you provide the output of
ng version?mirobo commentedon Dec 12, 2023
Thanks, sure:
To give you a clearer view:
We have 170+ buildable libraries and each library has a folder "src" with the actual code and a folder "cypress" which contains e2e-tests, pageobjects, and so on. Then we have Jest- and Cypress-Component-Tests that are within the "src" folder, right besides each specific component or util.
Everytime I change a pageobject, e2e-test, jest-test or one of the Cypress-tests generates an output within that library (i.e. "my-lib/reports"), a rebuild was triggered with webpack (and also with vite).
Edit:
This was my exclusion list
alan-agius4 commentedon Dec 12, 2023
In the past, we didn't offer support for excluding files from the watcher, and it's not a feature we intend to introduce. However, it does seems there might be a bug in ng-packagr causing a library rebuild when a non-compilation file like
my-lib/reportsis modified, resulting in an unnecessary application build.If this is the case, I recommend filing an issue on https://github.com/ng-packagr/ng-packagr/.
mirobo commentedon Dec 14, 2023
I'm trying to figure out how the files are marked as files to consider in the build with ESBuild.
In build-action.js, I added some code to log the files that triggered a change:
I see that spec-Files and totally unrelated files show up here. Using
--verboseon the serve command I also see that unrelated HTML-files trigger a rebuild (they were stored within a libs-folder there other Angular libs reside).The search led me to https://github.com/angular/angular-cli/blob/main/packages/angular_devkit/build_angular/src/tools/esbuild/bundler-execution-result.ts#L91 and codeBundleCache here https://github.com/angular/angular-cli/blob/main/packages/angular_devkit/build_angular/src/builders/application/execute-build.ts#L69
But then it gets blurry. I see the reference to the evn variable
NG_BUILD_WATCH_ROOT, but I didn't set this variable.From the side of ESBuild I didn't find out anything.. I see that you can give ESBuild entrypoints, but that's it. I don't see how other files are included in the watched files..
alan-agius4 commentedon Dec 14, 2023
Likely this is caused by some misconfiguration in your project:
mirobo commentedon Dec 15, 2023
We have TSConfigs that necessarily reference spec files and Cypress tests. The setup is done with NX:
tsconfig.json in the root folder of the library:
and then tsconfig.spec.json and cypress/tsconfig.json include Jest- and Cypress-Tests but have different settings for the types, (for cypress/tsconfig.json ->
"types": ["cypress", "node", "cypress-axe"],).When I running
nx/ng serveit seems that only the main "tsconfig.app.json" is respected anyways (I saw this because in one library there was a problem with an import usingrequire, so I switched it to CommonJS (because there seem to be no alternatives forhttps://github.com/nx-js/compiler-util-> I fixed it withimport { compileCode, expose } from '@nx-js/compiler-util/dist/cjs.es6.js';). When doing a build, it would respect the tsconfig.json of that very library and when runningserveit would respecttsconfig.app.json. I had to addesModuleInteropto both configs.So I don't understand how the TSConfigs would affect the file watcher and how I could check how it is affecting the watcher.
But thanks to your hints I found the culprit: The Tailwind configuration.
It not documented very well on their website and according to some older issues, it seems that exclusions are not possible:
But NX, with its default setup, generates globPatterns that have some sort of exclusion:
**/!(*.stories|*.spec).{ts,html}Not I can extend this glob pattern and possibly create an MR for NX to extend these exclusions per default (to also match cypress.config.ts, my-util.test.ts, my-other-test.cy.ts).
As for now I'll ignore my huge ignore list for webpack and go on with the fixed Tailwind content globs and observe how the new watcher behaves with other files (as you see code-coverage output generated by Cypress was also a problem).
Last problem to solve now is using
@media screens(xs) {..}or the old@screens xs {..}in SCSS-files withangular plugin-sass:Previously we used
@screenwhich still is supported (but not documented anymore) and it works just fine with the Webpack bundler. Maybe it works because of some very well hidden configuration in that setup.In a new setup I tried it with Tailwind 3.0.2, 3.3.5 and 3.3.6 and none of these options work..
Possibly yet another misconfiguration.. :-(
alan-agius4 commentedon Dec 15, 2023
Glad to hear that you managed to fix the watching issues. The sass error is expected and valid in this case and is being thrown by the Sass compiler.
mirobo commentedon Dec 15, 2023
Is this a fundamental misunderstanding from my side? I thought I could use
@screenwithin SCSS. But I guess I need to study https://tailwindcss.com/docs/using-with-preprocessors#nesting and see what should actually work and what shouldn't.But still, it is very confusing because our setup works with Webpack and Tailwind (I don't know why it works) and it doesn't work with ESBuild. So something in the bundler must have changed too, since I didn't update Tailwind in my real project. Any ideas/hints other than to delete everything Tailwind-related and start from scratch? 😅
alan-agius4 commentedon Dec 15, 2023
This should not work when when using SCSS with both webpack and esbuild based builder. This is because the Sass compiler runs before Tailwind and the latter is only invoked if the Sass compilation is successfully.
In this cases the error is correct, the fact that it worked, was likely a bug in the Sass compiler that was fixed.
Example of the error with Webpack when using Angular CLI version 17
angular-automatic-lock-bot commentedon Jan 19, 2024
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.