3

I am having trouble linking to files that are in the node_modules folder (both in link tags and script tags) in my index.html file. My project is Angular2 based, and I used the Angular CLI to generate the project and its file structure.

The index.html file is in the src folder, which is adjacent to the node_modules folder that contains the files I want to link to.

Currently for the relative path I'm using ../ to go back up a folder but it's not working, as the console is giving me errors for the link tag and both script tags in index.html.

Can someone help me with the correct file paths? Thanks.

screenshot of index.html

4
  • Attach the screen shot of browser console. Commented Sep 29, 2016 at 13:35
  • i.sstatic.net/wZOYa.png Commented Sep 29, 2016 at 13:40
  • Try putting them in app.scripts in angular-cli.json instead. "scripts" : [ "../node_modules/jquery/dist/jquery.min.js" ] Commented Sep 29, 2016 at 13:44
  • Thank you, that worked for the script tags! But what about the link tag to the file that's also in the node_modules folder? Would that go somewhere else as well? Commented Sep 29, 2016 at 13:51

1 Answer 1

3

It's convenient to use the angular-cli.json file for including styles (<link>) and scripts (<script>) to your index.html.

Just use apps[0].scripts for scripts linking and similarly apps[0].styles for styles.

Another way is to include your stylesheets directly to the styles.css/scss/less file located in your src/ dir.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.