How to use node_modules path or third party assets in angular files.

Some times we need to use assets from node_modules in our angular project files.

For example, you are using a third party package and you want to import css files from it in your index.html

If you try to import like this, it gives error:

<link …


This content originally appeared on DEV Community and was authored by Lokesh daiya

Some times we need to use assets from node_modules in our angular project files.

For example, you are using a third party package and you want to import css files from it in your index.html

If you try to import like this, it gives error:

<link href="./node_modules/some_packge_name/assets/style.css">

So how to resolve this issue ??

We can tell angular to copy required files in build.

We can add glob in angular.json for assets:

build": {
          .....
           "assets": [
...
              {
                "glob": "**/*",
                "input": "./node_modules/some_packge_name/assets",
                "output": "./custom-assets"
              }
            ],
...
}

input: Path of your assets folder in node_modules
output: Path you want to use in your application.

now we can use it in our index.html as below:

<link href="./custom-asssets/style.css">

If you want to use images from some package, you can use it as shown below:

 <img src="/custom-assets/some-img-file.png" />

Hope you guys find these resources hopeful!


This content originally appeared on DEV Community and was authored by Lokesh daiya


Print Share Comment Cite Upload Translate Updates
APA

Lokesh daiya | Sciencx (2021-03-20T07:34:42+00:00) How to use node_modules path or third party assets in angular files.. Retrieved from https://www.scien.cx/2021/03/20/how-to-use-node_modules-path-or-third-party-assets-in-angular-files/

MLA
" » How to use node_modules path or third party assets in angular files.." Lokesh daiya | Sciencx - Saturday March 20, 2021, https://www.scien.cx/2021/03/20/how-to-use-node_modules-path-or-third-party-assets-in-angular-files/
HARVARD
Lokesh daiya | Sciencx Saturday March 20, 2021 » How to use node_modules path or third party assets in angular files.., viewed ,<https://www.scien.cx/2021/03/20/how-to-use-node_modules-path-or-third-party-assets-in-angular-files/>
VANCOUVER
Lokesh daiya | Sciencx - » How to use node_modules path or third party assets in angular files.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/20/how-to-use-node_modules-path-or-third-party-assets-in-angular-files/
CHICAGO
" » How to use node_modules path or third party assets in angular files.." Lokesh daiya | Sciencx - Accessed . https://www.scien.cx/2021/03/20/how-to-use-node_modules-path-or-third-party-assets-in-angular-files/
IEEE
" » How to use node_modules path or third party assets in angular files.." Lokesh daiya | Sciencx [Online]. Available: https://www.scien.cx/2021/03/20/how-to-use-node_modules-path-or-third-party-assets-in-angular-files/. [Accessed: ]
rf:citation
» How to use node_modules path or third party assets in angular files. | Lokesh daiya | Sciencx | https://www.scien.cx/2021/03/20/how-to-use-node_modules-path-or-third-party-assets-in-angular-files/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.