• Stars
    star
    893
  • Rank 51,128 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸš€ Deploy your πŸ…°οΈAngular app to GitHub pages directly from the Angular CLI! Available on NPM.

angular-cli-ghpages

NPM version CircleCI GitHub Actions The MIT License

Deploy your Angular app to GitHub Pages or any other Git repo directly from the Angular CLI! πŸš€

Screenshot

Table of contents:

  1. πŸ“– Changelog
  2. ⚠️ Prerequisites
  3. πŸš€ Quick Start (local development)
  4. βš™οΈ Installation
  5. πŸš€ Continuous Delivery
  6. πŸ“¦ Deployment Options
  7. πŸ“ Configuration File
  8. 🌍 Environments
  9. ⁉️ FAQ

πŸ“– Changelog

A detailed changelog is available in the releases section.

⚠️ BREAKING CHANGE (v1)

Starting with version 1 the option --configuration was renamed to --build-target.

BEFORE (does not work):

ng deploy --configuration=test

NOW:

ng deploy --build-target=test

If you use the old syntax, you will probably receive the following error:

An unhandled exception occurred: Configuration 'test' is not set in the workspace.


πŸ™ GitHub Actions is now properly supported alongside Travis CI and CircleCi. The token GITHUB_TOKEN is also supported. Learn everything you need to know in the following article:

Everything GitHub: Continuous Integration, Deployment and Hosting for your Angular App

⚠️ Prerequisites

This command has the following prerequisites:

  • Git 1.9 or higher (execute git --version to check your version)
  • Angular project created via Angular CLI v9.0.0 or greater
  • older Angular projects can still use the standalone program. See the documentation at README_standalone.

πŸš€ Quick Start (local development)

This quick start assumes that you are starting from scratch. If you already have an existing Angular project on GitHub, skip step 1 and 2.

  1. Install the latest version of the Angular CLI globally and create a new Angular project.

    npm install -g @angular/cli
    ng new your-angular-project --defaults
    cd your-angular-project
  2. By default the Angular CLI initializes a Git repository for you.
    To add a new remote for GitHub, use the git remote add command:

    git remote add origin https://github.com/<username>/<repositoryname>.git

    Hints:

    • Create a new empty GitHub repository first.
    • Replace <username> and <repositoryname> with your username from GitHub and the name of your new repository.
    • Please enter the URL https://github.com/<username>/<repositoryname>.git into your browser – you should see your existing repository on GitHub.
    • Please double-check that you have the necessary rights to make changes to the given project!
  3. Add angular-cli-ghpages to your project. For details, see the installation section.

    ng add angular-cli-ghpages
  4. Deploy your project to GitHub pages with all default settings. Your project will be automatically built in production mode.

    ng deploy --base-href=/<repositoryname>/

    Which is the same as:

    ng deploy your-angular-project --base-href=/<repositoryname>/

    Please be aware of the --base-href option. It is necessary when your project will be deployed to a non-root folder. See more details below.

  5. Your project should be available at https://<username>.github.io/<repositoryname>.
    Learn more about GitHub pages on the official website.

βš™οΈ Installation

angular-cli-ghpages can be installed via ng add. This will install the NPM package and add the necessary deploy configuration to your angular.json file.

ng add angular-cli-ghpages

The deploy config will be added for the specified defaultProject. If there is no defaultProject set and there is only one project in your workspace, this project will be used.

If you have multiple projects in one workspace, you can manually define the project name:

ng add angular-cli-ghpages --project MYPROJECTNAME

πŸš€ Continuous Delivery

If you run this command from a CI/CD environment, the deployment will most likely not work out of the box. For security reasons, those environments usually have read-only privileges or you haven't set up Git correctly. Therefore you should take a look at "personal access tokens" GH_TOKEN (which works everywhere) and the "installation access token" GITHUB_TOKEN (which is exclusively provided by GitHub actions). In short: a token replaces username and password and is a safer choice because a token can be revoked at any time.

All you need to do is to set an environment variable called GH_TOKEN (or PERSONAL_TOKEN) in your CI/CD environment. For GitHub Actions, you can also use the GITHUB_TOKEN which provides more security and requires no additional setup. All the tokens only work if the remote repository uses the HTTPS scheme. Tokens are generally not supported for Git over SSH.

If the current working directory is already a git repository, you don't need to specify the repository again. The current remote repository with the name origin will be used in this case. You can also override the repository setting using the --repo option.

If you specify all the three options (--repo, --name and --email), then angular-cli-ghpages will also work in directories that are not under version control at all.

ng deploy --repo=https://github.com/<username>/<repositoryname>.git --name="Your Git Username" [email protected]

(replace <username> and <repositoryname> with your username from GitHub and the name of your repository)

⚠️Important

Please do not disable the silent mode if you use tokens, otherwise people could read them in the output logs. If you are sure that your CI/CD provider does not display secrets on the console (this applies to CircleCI / Travis CI and Github Actions), you are welcome to disable silent mode.

ℹ️ Note for GitHub Actions

The GITHUB_TOKEN (installation access token) will only trigger a release of a new website if the action runs in a private repository. In a public repo, a commit is generated, but the site does not change. See this GitHub Community post for more info. If your repo is public, you must still use the GH_TOKEN (personal access token).

πŸ“¦ Deployment Options

--base-href

  • optional
  • Default: undefined (string)
  • Example:
    • ng deploy – The tag <base href="/"> remains unchanged in your index.html
    • ng deploy --base-href=/the-repositoryname/ – The tag <base href="/the-repositoryname/"> is added to your index.html

Specifies the base URL for the application being built. Same as ng build --base-href=/XXX/

ℹ️ Please read the next lines carefully, or you will get 404 errors in case of a wrong configuration!

A) You don't want to use a custom domain

If you don't want to use an own domain, then your later URL of your hosted Angular project should look like this: https://your-username.github.io/the-repositoryname. In this case you have to adjust the --base-href accordingly:

ng deploy --base-href=/the-repositoryname/
B) You want to use a custom domain

If you want to use your own domain, then you don't have to adjust --base-href. However, it is now necessary to set the --cname parameter!

ng deploy --cname=example.org

See the option --cname for more information!

--build-target

  • optional
  • Default: undefined (string)
  • Example:
    • ng deploy – Angular project is built in production mode
    • ng deploy --build-target=test – Angular project is using the build configuration test (this configuration must exist in the angular.json file)

If no buildTarget is set, the production build of the default project will be chosen. The buildTarget simply points to an existing build configuration for your project, as specified in the configurations section of angular.json. Most projects have a default configuration and a production configuration (commonly activated by using the --prod flag) but it is possible to specify as many build configurations as needed.

This is equivalent to calling the command ng build --configuration=XXX. This command has no effect if the option --no-build is active.

⚠️ BREAKING CHANGE (v1)

This option was called --configuration in previous versions.

BEFORE (does not work):

ng deploy --configuration=test

NOW:

ng deploy --build-target=test

--no-build

  • optional
  • Default: false (string)
  • Example:
    • ng deploy – Angular project is build in production mode before the deployment
    • ng deploy --no-build – Angular project is NOT build

Skip build process during deployment. This can be used when you are sure that you haven't changed anything and want to deploy with the latest artifact. This command causes the --build-target setting to have no effect.

--repo

  • optional
  • Default: URL of the origin remote of the current dir (assumes a Git repository)
  • Example: ng deploy --repo=https://github.com/<username>/<repositoryname>.git

This specifies the target repository. If none is given as an option, the repository is discovered from the current working directory.

By default, this command assumes that the current working directory is a Git repository, and that you want to push changes to the origin remote. If instead your files are not in a git repository, or if you want to push to another repository, you can provide the repository URL in the repo option.

ℹ️ Hint

Set an environment variable with the name GH_TOKEN / PERSONAL_TOKEN or GITHUB_TOKEN and it will be automatically added to the URL, if it uses the HTTPS shema (it must start with https://github.com). Tokens are generally not supported for Git over SSH (starts with [email protected]).

Learn more about "personal access tokens" here (GH_TOKEN) and about the "installation access token" here (GITHUB_TOKEN). PERSONAL_TOKEN is an alias for GH_TOKEN.

--message

  • optional
  • Default: Auto-generated commit [ci skip] (string)
  • Example: ng deploy --message="What could possibly go wrong?"

The commit message must be wrapped in quotes if there are any spaces in the text.
Some additional text is always added to the message, if the command runs on Travis CI, Circle CI or GitHub Actions.

--branch

  • optional
  • Default: gh-pages (string)
  • Example: ng deploy --branch=master

The name of the branch you'll be pushing to. The default uses GitHub's gh-pages branch, but this can be configured to push to any branch on any remote. You have to change this to master if you are pushing to a GitHub organization page (instead of a GitHub user page).

--name & --email

  • optional
  • Default: value of git config user.name and git config user.email
  • Example: ng deploy --name="Displayed Username" [email protected]

If you run the command in a repository without user.name or user.email Git config properties (or on a machine without these global config properties), you must provide user info before Git allows you to commit. In this case, provide both name and email string values to identify the committer.

--no-silent

  • optional
  • Default: silent true (boolean)
  • Example:
    • ng deploy – Logging is in silent mode by default.
    • ng deploy --no-silent – Logging shows extended information.

Logging is in silent mode by default. In silent mode, the error messages for git operations are always sanitized. (The message is always: 'Unspecified error (run without silent option for detail)')

The --no-silent option enables detailed error messages and extended console logging. Keep this untouched if the repository URL or other information passed to git commands is sensitive!

⚠️ WARNING

This option should be kept as it is if the repository URL or other information passed to Git commands is sensitive and should not be logged (== you have a public build server and you are using the token feature). By default the silent mode is enabled to avoid sensitive data exposure.

--no-dotfiles

  • optional
  • Default: dotfiles true (boolean)
  • Example:
    • ng deploy – Dotfiles are included by default.
    • ng deploy --no-dotfiles – Dotfiles are ignored.

The command includes dotfiles by default (e.g. .htaccess will be committed). With --no-dotfiles files starting with . are ignored.

Hint: This is super useful if you want to publish a .nojekyll file. Create such a file in the root of your pages repo to bypass the Jekyll static site generator on GitHub Pages. Static content is still delivered – even without Jekyll. This should only be necessary if your site uses files or directories that start with _underscores since Jekyll considers these to be special resources and does not copy them to the final site. β†’ Or just don't use underscores!

--cname

  • optional
  • Default: undefined (string) – No CNAME file is generated
  • Example:
    • ng deploy --cname=example.com

A CNAME file will be created enabling you to use a custom domain. More information on GitHub Pages using a custom domain.

--dry-run

  • optional
  • Default: false (boolean)
  • Example:
    • ng deploy – Normal behavior: Changes are applied.
    • ng deploy --dry-run – No changes are applied at all.

Run through without making any changes. This can be very useful because it outputs what would happen without doing anything.

πŸ“ Configuration File

To avoid all these command-line cmd options, you can write down your configuration in the angular.json file in the options attribute of your deploy project's architect. Just change the kebab-case to lower camel case. This is the notation of all options in lower camel case:

  • baseHref
  • buildTarget
  • noBuild
  • repo
  • message
  • branch
  • name
  • email
  • noSilent
  • noDotfiles
  • cname
  • dryRun

A list of all available options is also available here.

Example:

ng deploy --base-href=https://angular-schule.github.io/angular-cli-ghpages/ --name="Angular Schule Team" [email protected]

becomes

"deploy": {
  "builder": "angular-cli-ghpages:deploy",
  "options": {
    "baseHref": "https://angular-schule.github.io/angular-cli-ghpages/",
    "name": "Angular Schule Team",
    "email": "[email protected]"
  }
}

Now you can just run ng deploy without all the options in the command line! πŸ˜„

ℹ️ Hint

You can always use the --dry-run option to verify if your configuration is right. The project will build but not deploy.

🌍 Environments

We have seen angular-cli-ghpages running on various environments, like Travis CI, CircleCi or Github Actions. Please share your knowledge by writing an article about how to set up the deployment.

  1. GitHub Actions by Dharmen Shah
  2. Travis CI
  3. CircleCI

⁉️ FAQ

Before posting any issue, please read the FAQ first. See the contributors documentation at README_contributors if you want to debug and test this project.

License

Code released under the MIT license.


πŸš€ Powered by ngx-deploy-starter

Β© 2017-2022 https://angular.schule

This project is made on top of tschaub/gh-pages.
Thank you very much for this great foundation!

More Repositories

1

ngx-deploy-starter

Starter repository to create a new builder to utilize the `ng deploy` command πŸš€
TypeScript
54
star
2

demo-ssr-playground

βœ… Playground for SSR and Pre-Rendering with Angular
TypeScript
28
star
3

website-articles

πŸ“† repo serving our website
CSS
7
star
4

book-rating-ngrx

πŸš€ Everything NgRx, Demo Code for our Angular Connect mini-workshop
TypeScript
5
star
5

demo-api-codegen

πŸš€ Demo for the api codegen articles (swagger & graphql)
TypeScript
4
star
6

2019-02-angular-workshop-erlangen

πŸŽ“ Februar 2019: 5 Tage Inhouse-Workshop in Erlangen
TypeScript
3
star
7

2018-09-angular-workshop-jena

πŸŽ“ September 2018: 4 Tage Inhouse-Workshop in Jena
TypeScript
3
star
8

vscode-angular-schule-extension-pack

πŸ“‚ Our VSCode extension for Angular development
TypeScript
3
star
9

2024-10-angular-workshop-hannover

πŸŽ“ Oktober 2024: 6 Tage Advanced Remote-Workshop Hannover (mit Johannes Hoppe)
TypeScript
2
star
10

demo-angular-graphql

πŸš€ Demo for the "From 0 to 100 with Angular and GraphQL" talk
TypeScript
2
star
11

webcam-viewer

Simple fullscreen webcam viewer in a browser
JavaScript
2
star
12

2020-02-angular-workshop-leipzig-DTM

[DTM] πŸŽ“ Februar 2020: 4 Tage Inhouse-Workshop in Leipzig
TypeScript
2
star
13

book-rating-redux

πŸŽ‰ Demo for our talk about Angular with Redux
TypeScript
2
star
14

2022-11-angular-workshop-regensburg

πŸŽ“ November 2022: 3 Tage Inhouse-Workshop in Regensburg (mit Johannes Hoppe)
TypeScript
2
star
15

2023-05-angular-workshop-online

πŸ…°οΈ Mai 2023: 6 Tage offener Online-Workshop (mit Ferdinand Malcher)
TypeScript
2
star
16

2022-06-angular-workshop-essen

πŸŽ“ Juni/Juli 2022: 6 Tage Remote-Workshop Essen (mit Johannes Hoppe)
TypeScript
2
star
17

2022-10-angular-workshop-gruenberg

πŸŽ“ Oktober 2022: 6 Tage Remote-Workshop GrΓΌnberg (mit Johannes Hoppe)
TypeScript
2
star
18

2017-07-angular-meetup-jena

πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦ Talk und Workshop // Softwerkskammer Jena // 20.07.2017
TypeScript
2
star
19

2020-02-angular-htwk-leipzig

🏒 Februar 2020: Workshop an der HTWK Leipzig
TypeScript
2
star
20

2018-09-jugsaxonyday

πŸ• Demo-App fΓΌr den Talk "Moderne Webentwicklung mit Angular" von Ferdinand Malcher auf dem JUG Saxony Day 2018
TypeScript
2
star
21

2019-09-angular-workshop-thun

πŸŽ“ September 2019: 2 Tage Inhouse-Workshop in Thun (CH)
TypeScript
2
star
22

2020-01-angular-workshop-heidelberg

πŸŽ“ Januar 2020: 4 Tage Inhouse-Workshop in Heidelberg
TypeScript
1
star
23

2021-05-angular-testing-duesseldorf

πŸŽ“ 5. Mai 2021: Remote-Workshop Angular Testing / DΓΌsseldorf (mit Ferdinand Malcher)
TypeScript
1
star
24

2018-05-angular-workshop-bad-lippspringe

πŸŽ“ Mai 2018: 3 + 2 Tage Inhouse-Workshop in Bad Lippspringe
TypeScript
1
star
25

2020-02-angular-workshop-heidelberg

πŸ…°οΈ Februar 2020: 4 Tage Offener Workshop in Heidelberg
TypeScript
1
star
26

2022-03-angular-workshop-online

πŸ…°οΈ MΓ€rz 2022: 6 Tage offener Online-Workshop (mit Ferdinand Malcher)
TypeScript
1
star
27

2018-10-angular-workshop-jena

πŸŽ“ Oktober 2018: 4 Tage Inhouse-Workshop in Jena
TypeScript
1
star
28

2018-11-angular-workshop-mosbach

πŸŽ“ November 2018: 2 Tage Mini-Workshop / Vorlesung in Mosbach
TypeScript
1
star
29

2019-11-angular-workshop-leipzig

πŸ…°οΈ November 2019: 4 Tage Offener Workshop in Leipzig
TypeScript
1
star
30

demo-one-app-per-customer

πŸš€ Demo for the article: "One app per customer"
TypeScript
1
star
31

2020-02-angular-workshop-schiltach

πŸŽ“ Februar 2020: 4 Tage Inhouse-Workshop in Schiltach
TypeScript
1
star
32

2019-10-angular-workshop-berlin

πŸŽ“ Oktober 2019: 4 Tage Inhouse-Workshop in Berlin
TypeScript
1
star
33

2020-05-rxjs-workshop-online-ish

πŸ‘©β€πŸ’» Mai 2020: 2 Tage Online-Workshop RxJS und Angular
TypeScript
1
star
34

2021-05-angular-workshop-senftenberg

πŸŽ“ Mai 2021: 6 Tage Remote-Workshop Senftenberg (mit Ferdinand Malcher)
TypeScript
1
star
35

2021-07-angular-workshop-bergisch-gladbach

πŸŽ“ Juli 2021: 6 Tage Remote-Workshop Bergisch Gladbach (mit Johannes Hoppe)
C#
1
star
36

2019-02-angular-workshop-niederolm

πŸŽ“ Februar 2019: 4 Tage Inhouse-Workshop in Nieder-Olm
TypeScript
1
star
37

2021-08-rxjs-workshop-online-gmh

πŸ‘©β€πŸ’» August 2021: Online-Workshop RxJS, NgRx und Angular – mit Ferdinand Malcher
TypeScript
1
star
38

2017-12-angular-workshop-neuss

πŸŽ“ Dezember 2017: 4 Tage Inhouse-Workshop in Neuss
TypeScript
1
star
39

2021-01-angular-workshop-badsoden

πŸŽ“ Januar 2021: 6 Tage Remote-Workshop Bad Soden (mit Ferdinand Malcher)
TypeScript
1
star
40

2019-12-angular-workshop-kassel

πŸŽ“ Dezember 2019: 4 Tage Inhouse-Workshop in Kassel
TypeScript
1
star
41

2019-11-angular-workshop-jena

πŸŽ“ November 2019: 4 Tage Inhouse-Workshop in Jena
1
star
42

2019-02-angular-workshop-jena

πŸŽ“ Februar 2019: 4 Tage Inhouse-Workshop in Jena
TypeScript
1
star
43

2019-07-angular-workshop-duesseldorf

πŸŽ“ Juli 2019: 4 Tage Inhouse-Workshop in DΓΌsseldorf
TypeScript
1
star
44

2019-06-angular-workshop-heidelberg

πŸ…°οΈ Juni 2019: 4 Tage Offener Workshop in Heidelberg
TypeScript
1
star
45

2017-03-angular-workshop-spartakiade

πŸ…°οΈ MΓ€rz 2017: Offener Workshop zur Spartakiade in Berlin #spartakiade
TypeScript
1
star
46

2022-06-angular-workshop-leverkusen

πŸŽ“ Juni/Juli 2022: 7 Tage Remote-Workshop Leverkusen (mit Johannes Hoppe)
TypeScript
1
star
47

2021-04-rxjs-workshop-online-ish

πŸ‘©β€πŸ’» April 2021: Online-Workshop RxJS, NgRx und Angular
TypeScript
1
star
48

2024-04-angular-workshop-wil

πŸŽ“ April/Mai 2024: 6 Tage Remote-Workshop Wil (CH) (mit Johannes Hoppe)
TypeScript
1
star
49

2021-03-angular-workshop-online

πŸ…°οΈ MΓ€rz 2021: 6 Tage offener Online-Workshop (mit Ferdinand Malcher)
TypeScript
1
star
50

2018-09-angular-workshop-heidelberg

πŸ…°οΈ September 2018: 3 + 1 Tage Offener Workshop in Heidelberg
TypeScript
1
star
51

2024-05-angular-workshop-stuttgart

πŸŽ“ Mai 2024: 4 Tage PrΓ€senz-Workshop Stuttgart (mit Ferdinand Malcher)
TypeScript
1
star
52

2023-09-angular-workshop-online

πŸ…°οΈ September 2023: 6 Tage offener Online-Workshop (mit Ferdinand Malcher)
TypeScript
1
star
53

2024-06-angular-workshop-bremen

πŸŽ“ Juni 2024: 5 Tage PrΓ€senz-Workshop Bremen (mit Johannes Hoppe)
TypeScript
1
star