angular-cli: Stylesheet from (npm) linked package not loaded correctly
OS
Tested on both Windows 7 and Linux (Fedora 24)
Version
$ ng --version
angular-cli: 1.0.0-beta.22-1
node: 4.6.1
os: linux x64
The app was created using CLI.
Repro steps
- Install a package containing a stylesheet (say bootstrap-sass, actually any package will do) globally via npm.
- git clone https://github.com/twbs/bootstrap-sass.git into a working directory, cd to that working directory and perform
npm link
command. - ng new project in another separate directory, cd to the newly create project directory and perform
npm link bootstrap-sass
. This will create abootstrap-sass
symlink in node_modules pointing to the local git repository. - Modify angular-cli.json to reference the stylesheet in the linked package.
"styles": [
"../node_modules/bootstrap-sass/assets/stylesheets/_bootstrap.scss",
"styles.scss"
],
ng serve
and observe that styles from bootstrap is not exported correctly in the index page.ng build
and observe that the generated styles.bundle.js does not do “exports.push()”.
The log given by the failure
There was no error log, webpack declared the “bundle is now valid”.
Mention any other details that might be useful
Using normal npm install approach does not have this issue. i.e. after npm unlink bootstrap-sass && npm install bootstrap-sass
then all is fine.
Use case: I have a forked gentelella
repository locally to fix some of the issues I found, so I cannot just simply npm install it in my project. Using npm link approach as I outlined above should work. It seems angular-cli (or webpack, I am not sure) is being confused by symlink. As a temporary workaround, I replace the stylesheet reference in the angular-cli.json with an absolute path to the stylesheet file in the local git repo.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 11
- Comments: 27 (12 by maintainers)
Commits related to this issue
- fix(@angular-devkit/build-angular): correctly resolve symlinked global styles entrypoints With this change we resolve the global stylesheet entrypoint path to use the realpath instead of the symlink ... — committed to angular/angular-cli by alan-agius4 3 years ago
- fix(@angular-devkit/build-angular): correctly resolve symlinked global styles entrypoints With this change we resolve the global stylesheet entrypoint path to use the realpath instead of the symlink ... — committed to angular/angular-cli by alan-agius4 3 years ago
@filipesilva As mentioned in this comment the fix only appears to apply to SCSS/CSS/JS, but not to static assets like font files (used by font-awesome, material-design-icons, etc).
Should we open a separate issue for that?
Using
@import "../node_modules/gentelella/src/scss/custom";
in thestyles.scss
as the workaround now. The sass preprocessor handles the symlink well.I think I’ve also run into something related to this: in the “styles” section of angular.json, if I include a CSS file that is actually a symlink, angular builds the project OK and includes that symlinked CSS file, but if I make a change in the targeted CSS file, angular does not pick up the change and reload the new style.
Steps:
I hit what I thought was a similar issue and used the shell script below to build and example environment to work in.
Using the created app I tracked the fact the the stylesheets where being loaded by webpack, but by their canonical absolute path.
This (eventually) lead me to looking at webpack bugs and I found this , https://github.com/webpack/webpack/issues/8824 , which then lead me to the webpack resolveSymlink option.
With a bit more digging I can make the test project I generated pass the tests by changing the options for the test command in angular.json (and other commands will need it as well) to add
It appears there might be some downside of symlink paths not being watched correctly with this option, and the webpack bug does suggest the issue could also be fixed by adding an extra reference to absolute canonical path to the webpack loader spec as well as the path ‘through’ the symlink.
Hope this help…
+1 same here
Now that https://github.com/angular/angular-cli/issues/3401 is done, it should be feasible to do something like what was originally requested:
Can you see if this solves it?