Angular 2 CLI - Deployment to github user page shows readme page

寵の児 提交于 2020-06-14 04:09:29

问题


I have deployed my angular 2 project to my github user page via angular CLI. I tried out the steps from official angular 2 cli page. However when I try to access the github url it shows the contents of readme file. Both the user page and user-page/baseUrl does the same.

I have used routing which works in the local environment. I’m not sure if I should modify the production environment variables or baseUrl.

Link to the repository: https://github.com/nirmalks/nirmalks.github.io


回答1:


You should commit dist/ folder generated by ng build in master branch of your repo. As I can see you have your angular source code commited there. Unfortunatey you cannot keep your source code in your master branch.

the complete commit command with ngh will be
ng build --prod --base-href="YOUR_GITHUB_USER_NAME.github.io"
and then
ngh --message="MESSAGE" --branch="master"

I have published the same in my repo you can check my website

Also, the source code repo is this




回答2:


Step 1:

First install the angular-cli-ghpages globally:

$ npm install -g angular-cli-ghpages

build your project and set the correct base href location:

ng build --prod --base-href="https://user-name.github.io/repo/"

Then:

$ ngh

Step 2: In github.com --> Go to your repp --> Setting --> Choose publish with gh-pages branch ==> Save

Step 3: You need to run ng server in terminal to start your local project.

Step 4: And then come back to https://username.github.io/project/"




回答3:


Because you're using a user/organisation repository of the form username.github.io github automatically publish your master branch, it is also using the readme file as an index.

If you want to publish your gh-pages branch, you need to go in your repository settings and change source branch in the github pages tab to gh-pages




回答4:


Deploy Angular with GitHub pages

First install angular-cli-ghpages globally

npm install -g angular-cli-ghpages

Angular CLI with the --base-href

ng build --prod --base-href="https://<user-name>.github.io/<repo>/"

To publish the app

ngh

just try on git you will be satisfied




回答5:


when you install the npm install -g angular-cli-ghpages that time github created a gh-pages branch in your repository, you need to only select that gh-pages branch option

Go to your repp → Setting → GitHub Pages &rarrl select gh-pages branch




回答6:


1. Create Github repo

If you had not created a Github repository prior to this, go ahead and create a repo in your Github account. After creating the repo, commit all your changes and push them to the repository you have created.

If you had created your repo prior to this, also commit and push all your changes to your Github repository.

2. Install angular-cli-ghpages

Run:

$ npm i angular-cli-ghpages --save-dev

if you hadn't installed angular-cli-ghpages.

3. Run build

Run:

$ ng build --prod --base-href "https://GithubUserName.github.io/GithubRepoName/" 

4. Deploy to gh-pages

Run:

$ npx angular-cli-ghpages --dir=dist/Project-name

Make sure you put the name of the project in the place of Project-name.You can find this in the angular.json file under defaultProject which is at the bottom of the file.

Now if you visit https://GithubUserName.github.io/GithubRepoName/ you should see your application running remotely,which means it has successfully been published on gh-pages.



来源:https://stackoverflow.com/questions/41658881/angular-2-cli-deployment-to-github-user-page-shows-readme-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!