2

I have an angular2 application which uses nodejs server api's. I build the app using nd b, which created the files in dist folder. Where can I specify the production url for the production build, so that all the css, js files loads properly. enter image description here

And also, whether I need apache server to host these build. Or Can I use node server itself to host it?

Index.html:

<!doctype html>
<html>
<head>
  <base href="/">
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Demo</title>
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link rel="stylesheet" href="assets/styles/css/custom.css"/>
  <script src="assets/vendor/pace/pace.js"></script>
</head>
<body>
  <app-root>
    <div class="loading"></div>
  </app-root>
</body>
</html>

Thanks

2 Answers 2

8

By analyzing your html file i am seeing an issue with the <base>tag.

You need to provide ./ instead of /which is wrong. Corrected html document is given below.

<!doctype html>
<html>
<head>
  <base href="./"> <!-- use ./ instead of / -->
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>SHEPHERD SHIELD</title>
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link rel="stylesheet" href="assets/styles/css/custom.css"/>
  <script src="assets/vendor/pace/pace.js"></script>
</head>
<body>
  <app-root>
    <div class="loading"></div>
  </app-root>
</body>
</html>

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

1 Comment

Yes, @KrutikJayswal. i was answering the question and didn't noticed the onscreen execution pane
2

For development and testing purpose you can specify the urls for the css from the dist folder. If you are going for production, then you can copy the minified version of css and js files and put them in style and js folders for example, also set the urls in the html file from these folders.

7 Comments

I have successfully build the angular2 app, but I want to host it in a /var/www/v1 ie, ip/v1 (ip: 00.00.0.0), Where can I specify the host url : localhost/testproject in the environment file? ng g command build the files in dist folder, but when I am copying those files into /var/www/v1, it is showing, unable to load js, css files ie trying to load from localhost/styles/custom.css, actually it is existing in localhost/v1/styles/custom.css. I hope this is due the lag of url specification somewhere.
Are you able to check the Network tab in the developer tab of your browser.
Yes. What I have to check
The js, css files are trying to load from localhost, not from localhost/v1.
Please share your html file details
|

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.