最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular2 application build, but file not found while loading the css, js folders - Stack Overflow

programmeradmin6浏览0评论

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.

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

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.

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

Share Improve this question edited Feb 16, 2017 at 11:23 Sanjay Kumar N S asked Feb 15, 2017 at 7:18 Sanjay Kumar N SSanjay Kumar N S 4,7495 gold badges24 silver badges40 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 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>

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论