<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alain Boudard</title>
    <description>The latest articles on DEV Community by Alain Boudard (@aboudard).</description>
    <link>https://dev.to/aboudard</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F148151%2F7f7afcad-762e-459c-90fa-e749fa1f05ac.jpeg</url>
      <title>DEV Community: Alain Boudard</title>
      <link>https://dev.to/aboudard</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aboudard"/>
    <language>en</language>
    <item>
      <title>[Boost]</title>
      <dc:creator>Alain Boudard</dc:creator>
      <pubDate>Thu, 22 May 2025 12:46:12 +0000</pubDate>
      <link>https://dev.to/aboudard/-32f2</link>
      <guid>https://dev.to/aboudard/-32f2</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/ngrx/announcing-events-plugin-for-ngrx-signalstore-a-modern-take-on-flux-architecture-4dhn" class="crayons-story__hidden-navigation-link"&gt;Announcing Events Plugin for NgRx SignalStore: A Modern Take on Flux Architecture&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;
          &lt;a class="crayons-logo crayons-logo--l" href="/ngrx"&gt;
            &lt;img alt="NgRx logo" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F5016%2Fa8dc55b2-63c3-4e96-917c-2c18727a650a.png" class="crayons-logo__image"&gt;
          &lt;/a&gt;

          &lt;a href="/markostanimirovic" class="crayons-avatar  crayons-avatar--s absolute -right-2 -bottom-2 border-solid border-2 border-base-inverted  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F455571%2F51bedc18-8017-4569-a25d-30a74074bcb9.jpg" alt="markostanimirovic profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/markostanimirovic" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Marko Stanimirović
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Marko Stanimirović
                
              
              &lt;div id="story-author-preview-content-2469924" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/markostanimirovic" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F455571%2F51bedc18-8017-4569-a25d-30a74074bcb9.jpg" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Marko Stanimirović&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

            &lt;span&gt;
              &lt;span class="crayons-story__tertiary fw-normal"&gt; for &lt;/span&gt;&lt;a href="/ngrx" class="crayons-story__secondary fw-medium"&gt;NgRx&lt;/a&gt;
            &lt;/span&gt;
          &lt;/div&gt;
          &lt;a href="https://dev.to/ngrx/announcing-events-plugin-for-ngrx-signalstore-a-modern-take-on-flux-architecture-4dhn" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;May 12 '25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/ngrx/announcing-events-plugin-for-ngrx-signalstore-a-modern-take-on-flux-architecture-4dhn" id="article-link-2469924"&gt;
          Announcing Events Plugin for NgRx SignalStore: A Modern Take on Flux Architecture
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ngrx"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ngrx&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/angular"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;angular&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/ngrx/announcing-events-plugin-for-ngrx-signalstore-a-modern-take-on-flux-architecture-4dhn" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/exploding-head-daceb38d627e6ae9b730f36a1e390fca556a4289d5a41abb2c35068ad3e2c4b5.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;52&lt;span class="hidden s:inline"&gt; reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/ngrx/announcing-events-plugin-for-ngrx-signalstore-a-modern-take-on-flux-architecture-4dhn#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              11&lt;span class="hidden s:inline"&gt; comments&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            6 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>ngrx</category>
      <category>angular</category>
    </item>
    <item>
      <title>Adding scss assets to Angular library</title>
      <dc:creator>Alain Boudard</dc:creator>
      <pubDate>Thu, 30 Nov 2023 15:10:22 +0000</pubDate>
      <link>https://dev.to/aboudard/adding-scss-assets-to-angular-library-gjc</link>
      <guid>https://dev.to/aboudard/adding-scss-assets-to-angular-library-gjc</guid>
      <description>&lt;p&gt;In a previous article, I was talking about some ways to &lt;a href="https://medium.com/@coco-boudard/adding-css-assets-to-angular-library-c22fd3a47c5d" rel="noopener noreferrer"&gt;include assets in an Agular library&lt;/a&gt;. Let’s go a little further, and see how we can handle scss files and compile in the application and not in the library.&lt;/p&gt;

&lt;h3&gt;
  
  
  The example of bootstrap
&lt;/h3&gt;

&lt;p&gt;One example we can name is how we can integrate bootstrap style to our application. It goes like this :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install bootstrap&lt;/li&gt;
&lt;li&gt;Reference bootstrap scss in angular.json or global styles.scss&lt;/li&gt;
&lt;li&gt;Eventually override some variables of the library&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: if you import such a scss file like bootstrap, you may override some variables, only if you import the stylesheet in your styles.scss (or another one) of your project. It won’t work from angular.json.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2rrhs8sdpsefqjzlosm6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2rrhs8sdpsefqjzlosm6.png" alt="This way we can override variables used in bootstrap scss."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The goal of our application
&lt;/h3&gt;

&lt;p&gt;The main goal here is to have an Angular application that doesn’t require the library scss to be previously built. We will see what options we have to let the application do the job. The library will not only expose &lt;strong&gt;scss&lt;/strong&gt; files but also &lt;strong&gt;images&lt;/strong&gt; and &lt;strong&gt;fonts&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This means that our library will not expose compiled css to the outer world, but sometimes, and it can be convenient, a library can expose both the scss &lt;strong&gt;and&lt;/strong&gt; the css.&lt;/p&gt;

&lt;p&gt;Of course that means that each time our application will build, this task will be running, but as we might already know, Angular build system does separate typescript and style build.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Angular workspace
&lt;/h2&gt;

&lt;p&gt;Let’s create a workspace with both a library and an application.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

ng new ng-assets-wk --create-application false
cd ng-assets-wk
ng g library @abo/ng-lib
ng g application ng-app -routing --style scss


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We can write some scripts to build both library and application :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

"build:lib": "ng build --project @abo/ng-lib",
"watch:lib": "ng build --watch --configuration development --project @abo/ng-lib",
"build:app": "ng build --project ng-app",
"watch:app": "ng build --watch --configuration development --project ng-app",


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Styles in the application
&lt;/h3&gt;

&lt;p&gt;In the &lt;code&gt;src/styles.scss&lt;/code&gt; file, we can add some basic style and reference a simple asset with variables.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fizsmjphzll5pq7ojg35y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fizsmjphzll5pq7ojg35y.png" alt="Override scss variables from Angular library"&gt;&lt;/a&gt;&lt;br&gt;
When we compile the application in &lt;code&gt;watch&lt;/code&gt; mode, we see that chunks are produced, both &lt;code&gt;js&lt;/code&gt; and &lt;code&gt;css&lt;/code&gt; files.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Famfrqu8ztnmf7q8457uw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Famfrqu8ztnmf7q8457uw.png" alt="Differential build of Angular resources"&gt;&lt;/a&gt;&lt;br&gt;
What can seem weird, is that when you modify your scss files (main file or variables), the message is pretty simple and doesn’t reflect the fact that &lt;code&gt;styles.css&lt;/code&gt; output has indeed been updated.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr4vmwbvdyml87ap4lv5g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr4vmwbvdyml87ap4lv5g.png" alt="Angular build output after styles.scss modification&amp;lt;br&amp;gt;
"&gt;&lt;/a&gt;&lt;br&gt;
Let’s note that there is a difference in the build output when you alter any of the source code, like a component, wether it’s &lt;code&gt;typescript&lt;/code&gt;, &lt;code&gt;html&lt;/code&gt; template or &lt;code&gt;scss&lt;/code&gt; file, which are not processed like the stylesheets referenced in &lt;code&gt;angular.json&lt;/code&gt; configuration file in the styles section :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpb141boiibasc1w4auk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpb141boiibasc1w4auk.png" alt="Angular build output after component modification&amp;lt;br&amp;gt;
"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This makes sense because Angular uses a default configuration for style isolation which is encapsulation: &lt;a href="https://angular.io/guide/view-encapsulation" rel="noopener noreferrer"&gt;ViewEncapsulation.Emulated&lt;/a&gt; that would prevent styles declared for a component to spread to other components.&lt;/p&gt;
&lt;h3&gt;
  
  
  Styles in the library
&lt;/h3&gt;

&lt;p&gt;Ok, now we want to add scss files to our library, and expose them to our application. Let’s create an assets folder in the libray and put some files in it:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnqodmlzz2oarn76i7w8z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnqodmlzz2oarn76i7w8z.png" alt="Declare scss variables in Angular library"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: if you want to be able to override your scss variables, you would need to use the keyword &lt;code&gt;!default&lt;/code&gt; like here, in the first declaration of your variable.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s add this folder, and all files in it, to the &lt;code&gt;ng-package.json&lt;/code&gt; file of the library. You can &lt;a href="https://github.com/ng-packagr/ng-packagr/blob/main/docs/copy-assets.md" rel="noopener noreferrer"&gt;find more information here&lt;/a&gt; about why we should declare this &lt;code&gt;assets&lt;/code&gt; property.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

  "assets": [
    "./assets/**/*.*"
  ]


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;During the &lt;strong&gt;build of the library&lt;/strong&gt;, the folder should be exported in the dist folder. Following a &lt;a href="https://medium.com/@coco-boudard/using-angular-cache-with-library-1744e5b8627b" rel="noopener noreferrer"&gt;previous article about Angular libraries&lt;/a&gt;, we will publish on a local &lt;strong&gt;Verdaccio server&lt;/strong&gt;. Now we can add the scss file to the list of styles of our application in the &lt;code&gt;angular.json&lt;/code&gt; (the point is to be as close as a production ready use case).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

"unpublish:lib": "npm unpublish @abo/ng-lib --registry http://localhost:4873/ --force",
"publish:lib": "ng build @abo/ng-lib &amp;amp;&amp;amp; cd dist/abo/ng-lib &amp;amp;&amp;amp; npm publish --registry http://localhost:4873/",
"install:lib": "npm install @abo/ng-lib --registry http://localhost:4873/",


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Don’t forget to remove the reference to the library path in the &lt;code&gt;tsconfig.json&lt;/code&gt; file.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9igbue2fvd5qghv8x3r8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9igbue2fvd5qghv8x3r8.png" alt="angular.json scss reference of the library"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: if you build your application in production mode, you might see something weird in the code inspector : the styles appear twice :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftace6z532aehy8ep5t30.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftace6z532aehy8ep5t30.png" alt="Angular inlineCritical configuration effect"&gt;&lt;/a&gt;&lt;br&gt;
This is due to an implicit configuration in &lt;code&gt;production&lt;/code&gt; build mode called &lt;strong&gt;inlineCritical&lt;/strong&gt; (turn this to false to disable if you want) that is meant to reduce the initial styled render of the page :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

"optimization": {
  "styles": {
    "minify": true,
    "inlineCritical": true
  }
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Anyway, if we run our application, the style of the library should be compiled with our application and be applied. Since we want to &lt;strong&gt;override the variables&lt;/strong&gt;, let’s try to use this stylesheet in our main &lt;code&gt;styles.scss&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;We remove the reference in the &lt;code&gt;angular.json&lt;/code&gt; file. Then we add a reference in the &lt;code&gt;styles.scss&lt;/code&gt; file :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fom17phg936eqon28dnfe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fom17phg936eqon28dnfe.png" alt="Add the library scss file in global application styles"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is working, obviously, but it doesn’t look great DX wise, so we will use the &lt;a href="https://angular.io/guide/angular-package-format#exports" rel="noopener noreferrer"&gt;export property of the Angular package format&lt;/a&gt;, in order to declare how we can access our scss resources. In this Angular documentation, it states that you need to declare this &lt;code&gt;exports&lt;/code&gt; property. As a result, we can use the entrypoint of the library in the scss import statement.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0xp0v5rdmfwtnx9gvf5x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0xp0v5rdmfwtnx9gvf5x.png" alt="package.json of the library and styles.scss of the application&amp;lt;br&amp;gt;
"&gt;&lt;/a&gt;&lt;br&gt;
This import is way much cleaner right ?&lt;/p&gt;

&lt;h3&gt;
  
  
  Add other files to the scss package
&lt;/h3&gt;

&lt;p&gt;Now, let’s add the most used files in combination with css: &lt;strong&gt;fonts and images&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In our library &lt;code&gt;assets&lt;/code&gt; folder, we can add an &lt;code&gt;/img&lt;/code&gt; folder with images, here we add two logos of Angular, and then we can simply reference these images in any CSS rule that we see fit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbpfiupikmdxde5boqxem.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbpfiupikmdxde5boqxem.png" alt="Simple css rules to use images in our components"&gt;&lt;/a&gt;&lt;br&gt;
Now we should be able to see our images in the page with some simple code :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;h1 class="logo next"&amp;gt;Angular next&amp;lt;/h1&amp;gt;
&amp;lt;h1 class="logo"&amp;gt;Angular&amp;lt;/h1&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw9xjii28mtftq3823si2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw9xjii28mtftq3823si2.png" alt="Angular logos"&gt;&lt;/a&gt;&lt;br&gt;
Now let’s add a custom font of our choice. Let’s go with &lt;a href="https://www.dafontfree.io/segoe-ui-font/" rel="noopener noreferrer"&gt;Segoe UI font&lt;/a&gt;. In our library &lt;code&gt;assets&lt;/code&gt; folder, we can add an &lt;code&gt;/fonts&lt;/code&gt; folder with the desired files. For the sake or readability, let’s create a dedicated &lt;code&gt;_fonts.scss&lt;/code&gt; file and reference it in our main library scss file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb7rk9ytx8j3mo69ogz2v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb7rk9ytx8j3mo69ogz2v.png" alt="scss fonts file in the angular library&amp;lt;br&amp;gt;
"&gt;&lt;/a&gt;&lt;br&gt;
In our main scss files, we import the fonts definition, and use the font in the body for a start, but anywhere you would want :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2er25fy6lnv5e12yyny7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2er25fy6lnv5e12yyny7.png" alt="Use the library font in the app"&gt;&lt;/a&gt;&lt;br&gt;
Now we can test in the browser if everything is ok, the font should be loaded in the devtools.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmwy03uqdkqhyz316r82s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmwy03uqdkqhyz316r82s.png" alt="The font from the library is loaded in the app&amp;lt;br&amp;gt;
"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Use the library scss in application components
&lt;/h3&gt;

&lt;p&gt;We saw that the components scss are not processed like the main styles declared from &lt;code&gt;angular.json&lt;/code&gt; section. But we still can use our declared variables (or any kind of tool, like mixin for example) in our components.&lt;/p&gt;

&lt;p&gt;Without any modification we could use the &lt;code&gt;@use&lt;/code&gt; annotation and consume our variables like that :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

@use "node_modules/@abo/ng-lib/assets/lib-variables" as lib;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftz9wo4ibrspct5htyscx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftz9wo4ibrspct5htyscx.png" alt="You can use @use or @import for the angular library scss&amp;lt;br&amp;gt;
"&gt;&lt;/a&gt;&lt;br&gt;
But again, that’s not very nice, we can then add another entry in our library package.json and have a better import in our component’s scss :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F90zk78zilv7ujmrxz9ip.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F90zk78zilv7ujmrxz9ip.png" alt="Expose scss variables from the angular library&amp;lt;br&amp;gt;
"&gt;&lt;/a&gt;&lt;br&gt;
With the same pattern, we can declare a &lt;code&gt;mixins&lt;/code&gt; file and use it through an export entry :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flc9kc2ibb4om8z12eppt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flc9kc2ibb4om8z12eppt.png" alt="Declare scss mixins in the angular library&amp;lt;br&amp;gt;
"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We saw that having a clean Angular library exposing scss resources is quite easy to configure. The main advantage of this method is to get rid of the css pre-build task in the library, and the maintainability of our custom variables and other uses of scss files. This is possible thanks to the scss capabilities of the Angular build, since we never had to launch a dedicated sass build.&lt;/p&gt;

&lt;p&gt;The use of the Angular endpoint reference is a plus for any library publisher.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/aboudard/ng-assets-wrk" rel="noopener noreferrer"&gt;https://github.com/aboudard/ng-assets-wrk&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ng-packagr/ng-packagr/blob/main/docs/copy-assets.md" rel="noopener noreferrer"&gt;https://github.com/ng-packagr/ng-packagr/blob/main/docs/copy-assets.md&lt;/a&gt;&lt;/p&gt;

</description>
      <category>angular</category>
      <category>scss</category>
      <category>library</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Using Angular cache with library</title>
      <dc:creator>Alain Boudard</dc:creator>
      <pubDate>Tue, 05 Sep 2023 07:40:00 +0000</pubDate>
      <link>https://dev.to/playfulprogramming-angular/using-angular-cache-with-library-1p96</link>
      <guid>https://dev.to/playfulprogramming-angular/using-angular-cache-with-library-1p96</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkl095eg7kug0p4rihhn3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkl095eg7kug0p4rihhn3.jpg" alt="Angular cache and library" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How the angular cache can interfere with the build of an application.&lt;/p&gt;

&lt;p&gt;I was reading this &lt;a href="https://balramchavan.medium.com/angular-cache-whats-inside-and-how-it-improves-angular-build-timing-on-local-and-ci-pipeline-f6821d22d67a" rel="noopener noreferrer"&gt;nice article about Angular cache&lt;/a&gt; (starting with version 13), and it reminded me that I stumbled upon an issue with this feature regarding the development of libraries. Basically, if you install a library with npm, if the source code of the library changes &lt;strong&gt;but not the version number&lt;/strong&gt;, what happens.&lt;/p&gt;

&lt;h2&gt;
  
  
  The project
&lt;/h2&gt;

&lt;p&gt;The Angular project we will be using consists of a workspace in which there will be a library and an application. Normally, when we develop an Angular library in the same workspace than the application, the local &lt;code&gt;tsconfig&lt;/code&gt; file takes care of telling Angular where the source code is so that we don’t need to install the library.&lt;/p&gt;

&lt;p&gt;For this project, we won’t be using the library directly, but we will publish it to any kind of registry compatible with npm and install it with npm install command.&lt;/p&gt;

&lt;p&gt;I had 2 tools available :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A free demo account with &lt;a href="https://jfrog.com/start-free/" rel="noopener noreferrer"&gt;jfrog.io&lt;/a&gt; that allows you to host your Artifactory registry in the cloud. You get a domain name like &lt;code&gt;https://username.jfrog.io&lt;/code&gt; and can publish right away.&lt;/li&gt;
&lt;li&gt;A local install of &lt;a href="https://verdaccio.org/" rel="noopener noreferrer"&gt;Verdaccio&lt;/a&gt; running next to our app.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The first option is really nice to test, but it’s limited in time, and our actual needs for this demo are very simple and Verdaccio is more than enough.&lt;/p&gt;

&lt;h2&gt;
  
  
  The local npm registry
&lt;/h2&gt;

&lt;p&gt;Using verdaccio is very simple :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install the package globally :
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g verdaccio
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Run verdaccio
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;verdaccio
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see the server running :&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98e641lovymumnyrq16w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98e641lovymumnyrq16w.png" alt="Local verdaccio registry running" width="800" height="183"&gt;&lt;/a&gt;&lt;br&gt;
And access your empty registry (note these commands for using this registry for later) :&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fauxnptj076qp9f4gvg7u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fauxnptj076qp9f4gvg7u.png" alt="verdaccio panel" width="800" height="255"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  The Angular workspace
&lt;/h2&gt;

&lt;p&gt;Let’s create a very simple angular workspace and add a library and an application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng new ng-lib --create-application false
ng g application testapp
ng g library @abo/testlib
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way we have both projects in the workspace. Let’s remove the path configuration from the &lt;code&gt;tsconfig&lt;/code&gt; file :&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6bj7fbw93w7lwx2vfpdk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6bj7fbw93w7lwx2vfpdk.png" alt="Angular library path in tsconfig" width="800" height="134"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This way, we will only use the library through the npm install, using our Verdaccio registry.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note : I’m aware that using an Angular library this way is not the proper way when you’re in &lt;code&gt;dev&lt;/code&gt; mode but this is not the point here.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  Publish our library with npm
&lt;/h3&gt;

&lt;p&gt;We must have followed the Verdaccio instructions to create the user we will login with. Then we can actually login, build the library and publish it :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm login - registry http://localhost:4873/
Username: admin
Password:
Email: (this IS public) abo@abo.com
Logged in as admin on http://localhost:4873/.*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Building and publishing the angular library with the &lt;code&gt;publish:lib&lt;/code&gt; script :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"ng"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ng"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"start:app"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ng serve testapp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"build:app"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ng build testapp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"build:lib"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ng build @abo/testlib"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"publish:lib"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ng build @abo/testlib &amp;amp;&amp;amp; cd dist/abo/testlib &amp;amp;&amp;amp; npm publish --registry http://localhost:4873/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"watch"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ng build --watch --configuration development"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ng test"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result must look like that : &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpaow6qg05zzx0qyyduux.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpaow6qg05zzx0qyyduux.png" alt="Angular build of a local library and publish to registry" width="800" height="1111"&gt;&lt;/a&gt;&lt;br&gt;
And in our Verdaccio console, we should see the library added to the registry :&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9qbl368riyywe1y7u0ka.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9qbl368riyywe1y7u0ka.png" alt="Verdaccio angular published library" width="800" height="220"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Add the library to the application
&lt;/h3&gt;

&lt;p&gt;This is pretty easy, let’s clean up the code of the placeholder Angular application, install our library via the registry and add the single component exposed to our home page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i @abo/testlib --registry http://localhost:4873/
...
+ @abo/testlib@0.0.1
added 1 package, removed 1 package and audited 992 packages in 8.988s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5t7d93g17uei9i3030mf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5t7d93g17uei9i3030mf.png" alt="The app.component with the library component" width="800" height="100"&gt;&lt;/a&gt;&lt;br&gt;
Be careful when adding your library because some IDEs have an auto-import feature that is a little bit too fast to find the proper import. You could have something like that (and this would trigger application recompile when unwanted) :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;TestlibModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../../../abo/testlib/src/lib/testlib.module&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you would only want this :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;TestlibModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@abo/testlib&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s alter the library and publish a new version to see the changes. I don’t use any automatic semantic versioning system, let’s use simply the &lt;code&gt;npm version&lt;/code&gt; command to upgrade the library and then re publish.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
    "upgrade-version:lib": "cd projects/abo/testlib &amp;amp;&amp;amp; npm version patch",
    "publish:lib": "ng build @abo/testlib &amp;amp;&amp;amp; cd dist/abo/testlib &amp;amp;&amp;amp; npm publish --registry http://localhost:4873/",
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check that your library is up to date in Verdaccio and re install in your Angular workspace (the new 0.0.2 version).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i @abo/testlib@0.0.2 --registry http://localhost:4873/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The application should show the new library version :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd1x6hgbv0u5pqq66ykbt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd1x6hgbv0u5pqq66ykbt.png" alt="New angular library version" width="569" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Publish the same version of Angular library
&lt;/h3&gt;

&lt;p&gt;Now, why would we want to publish the same version ? This could be a typical use case when you want to strictly control a release version, maybe aligned with a Maven package or something else. Anyway, let’s see what happens.&lt;/p&gt;

&lt;p&gt;If you alter your code in the library and simply try to re publish it, you will get an error like this :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb5ygu11cxnej350vuzv8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb5ygu11cxnej350vuzv8.png" alt="npm publish package same version error" width="800" height="178"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Most of the npm registries prevent from publishing the same version, some allow you to set options to override, but I didn’t find the option in verdaccio — if anyone knows about it, feel free to say it in the comments.&lt;/p&gt;

&lt;p&gt;Anyway, we will simply &lt;a href="https://docs.npmjs.com/unpublishing-packages-from-the-registry" rel="noopener noreferrer"&gt;unpublish the npm package&lt;/a&gt; and re publish it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
    "unpublish:lib": "npm unpublish @abo/testlib --registry http://localhost:4873/ --force",
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the tasks here are :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Alter the library component&lt;/li&gt;
&lt;li&gt;Unpublish the library on Verdaccio&lt;/li&gt;
&lt;li&gt;Re build et re publish the library&lt;/li&gt;
&lt;li&gt;Uninstall / re install the library in our Angular workspace&lt;/li&gt;
&lt;li&gt;Run the application and see the result&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd1x6hgbv0u5pqq66ykbt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd1x6hgbv0u5pqq66ykbt.png" alt="Still the same angular library version" width="569" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, there is no difference, the application was built with a previous verison of the library. Yet, when we take a look at the &lt;code&gt;package-lock.json&lt;/code&gt; we see that even if the version number is the same, the integrity property hash is different :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffssi49cx3atpg1l3iqgv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffssi49cx3atpg1l3iqgv.png" alt="Same npm version but different archive" width="800" height="293"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And actually, if we take a look in the &lt;code&gt;node_modules/@abo/testlib&lt;/code&gt; we see that the source code is the one we should expect :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdve13jr8c3xo2zwbx6dx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdve13jr8c3xo2zwbx6dx.png" alt="This is the proper updated source code of our Angular library" width="800" height="319"&gt;&lt;/a&gt;&lt;br&gt;
So, what happend ? Well as you guessed, the angular cache is responsible for this, let’s see how we can act on this.&lt;/p&gt;

&lt;p&gt;Remove the cache and then simply re start the application, which will force the build based on the actual node_modules version of the library. In the latest versions, there is a CLI command that doesn’t exist in version 13.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng cache clean

rimraf .\.angular\
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8evxw1u6cy3kkaijg4dx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8evxw1u6cy3kkaijg4dx.png" alt="Updated version of the Angular library" width="548" height="239"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of course this solution is far from excellent, but at least it works. The alternative would be to deactivate the cache on the build of the application (we don’t care about the build of the library, but &lt;strong&gt;since we are in a single workspace, no cache will be used at all&lt;/strong&gt;). We will try with a fourth version of the library and the following configuration :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng cache disable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx16rep2bcnzaz4dmcy65.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx16rep2bcnzaz4dmcy65.png" alt="Angular cache disabled" width="800" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we can rebuild the application anytime we want and whatever the version of the library, we will have the proper version. Of course it’s not a perfect solution because caching would improve our build time, but it’s good to know that even if the hash of the library is ok, even if the local source code is ok, well you really can’t know what version is actually stored in the cache, because if we look into the cache, we can see that the code is already precompiled by Angular :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng-lib\.angular\cache\13.3.11\babel-webpack (for example)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1bz4cc3w9opa4sxl17v1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1bz4cc3w9opa4sxl17v1.png" alt="Angular precompiled cache" width="800" height="290"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This local npm registry Verdaccio is really nice to test your Angular library publish skills and parameters. In many cases we don’t really care about the actual version of our libraries other than compatibility, but sometimes, well things happen.&lt;/p&gt;

&lt;h3&gt;
  
  
  Source code
&lt;/h3&gt;

&lt;p&gt;Source code for this article can be found here &lt;a href="https://github.com/aboudard/ng-lib" rel="noopener noreferrer"&gt;angular ng-lib&lt;/a&gt;&lt;/p&gt;

</description>
      <category>angular</category>
      <category>npm</category>
      <category>verdaccio</category>
      <category>library</category>
    </item>
  </channel>
</rss>
