npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

angular-sitemap-generator

v3.2.3

Published

Generates a sitemap.xml file for Angular projects

Downloads

220

Readme

🗺️ Angular Sitemap Generator

Angular Sitemap Generator is a CLI tool that automatically creates a sitemap.xml file for Angular projects.
It compiles your Angular project, analyzes your routing configuration, and generates a proper sitemap that helps search engines index your app’s pages.
It can also optionally generate MPA-like (Multi-Page Application) directory structures for hosting platforms like GitHub Pages, which don’t natively support Angular’s SPA routing.


🚀 Usage

Run it directly with npx (no installation required):

npx angular-sitemap-generator [url-path] [options]

Example:

npx angular-sitemap-generator https://borisonekenobi.github.io/DynoC-Docs/

The / at the end of the URL is optional — the generator adds it automatically if missing.


⚙️ CLI Options

| Short | Long Form | Description | |:------------|:-----------------------|:-----------------------------------------------------------------------------------------------| | -h | --help | Shows the help menu | | -v | --version | Displays the current package version | | -p <path> | --path <path> | Sets the path where the generated sitemap.xml file will be saved | | -c | --create-mpa-dir | Generates MPA-style directories in the public folder (for GitHub Pages and other static hosts) | | -m <path> | --mpa-path <path> | Sets a custom path for the generated MPA directories | | -r <path> | --robots-path <path> | Sets the path of the robots.txt file | | -g | --gen-robots | Generates a new robots.txt file if one doesn’t exist | | -u | --update-robots | Updates the existing robots.txt file to include a link to the sitemap |


🧩 What It Does

  1. Builds your Angular project the dist/ folder.
  2. Reads your routing configuration from src/app/app.routes.ts.
  3. Traverses all routes (including nested children) to build a list of valid URLs.
  4. Creates a sitemap.xml file and places it in your specified or default public/ folder.
  5. Optionally generates or updates a robots.txt file.
  6. (New!) Optionally creates MPA directories for each route — this means each route like /about gets its own /about/index.html file, preventing 404 errors on GitHub Pages and similar platforms.

🧱 MPA Directory Generation

When you include the -c (or --create-mpa-dir) flag, the generator will create directories for each route found in your Angular app.
These directories mimic a traditional multipage site so that static hosts can serve your app correctly.

For example, if your routes are:

export const routes: Routes = [
    {path: '', component: HomeComponent},
    {path: 'about', component: AboutComponent},
    {path: 'contact', component: ContactComponent}
];

Running:

npx angular-sitemap-generator https://example.com -c

Will create this structure inside your public folder:

public/
├── about/
│   └── index.html
├── contact/
│   └── index.html
├── sitemap.xml
├── robots.txt
└── index.html

Each generated index.html file is a copy of your built Angular index.html, ensuring navigation works even when users directly load a deep link such as https://example.com/about.

You can also control where these MPA directories are created using -m or --mpa-path:

npx angular-sitemap-generator https://example.com -c -m ./dist/mpa

📁 Project Requirements

This tool expects a default Angular project structure, specifically:

  • The routing file is located at:
    src/app/app.routes.ts
  • It must export a variable named routes of type Routes or Route[] from @angular/router:
    import { Routes } from '@angular/router';
    
    export const routes: Routes = [
      { path: '', component: HomeComponent },
      { path: 'about', component: AboutComponent },
      {
        path: 'blog',
        children: [
          { path: '', component: BlogListComponent },
          { path: ':id', component: BlogPostComponent }
        ]
      }
    ];

The generator will automatically walk through all routes and their children recursively.


📦 Output

After running the command, your project may contain:

project-root/
├── dist/
│   ├── [your-built-angular-project]
│   └── sitemap/
│       └── [temporary files to build sitemap.xml]
├── public/
│   ├── about/
│   │   └── index.html
│   ├── contact/
│   │   └── index.html
│   ├── robots.txt
│   └── sitemap.xml
└── src/
    └── app/
        └── app.routes.ts

🧠 Notes

  • The tool adds a trailing slash to your base URL if missing.
  • It automatically sets <lastmod> to the current UTC timestamp.
  • You can specify custom paths for both the sitemap, robots, and MPA directories.
  • Use --gen-robots to create a new robots.txt, or --update-robots to update an existing one.
  • Use --create-mpa-dir to generate static directories for each route (fixing 404 errors on GitHub Pages).
  • Compatible with Angular 18+ projects using standalone route definitions.

💡 Example Output

Running:

npx angular-sitemap-generator https://example.com -g -c

Generates:

  • A complete sitemap.xml
  • A robots.txt file with the sitemap link
  • An MPA-like directory structure to support static hosting

Your robots.txt will include:

User-agent: *
Allow: /

Sitemap: https://example.com/sitemap.xml

🧰 Development

If you want to work on or modify this tool locally:

git clone https://github.com/borisonekenobi/angular-sitemap-generator
cd angular-sitemap-generator
npm install
npm run build
node ./dist/index.js https://example.com

📄 License

MIT


Made with ❤️ by Boris Vasilev