{"id":22852057,"url":"https://github.com/janghye0k/generate-sitemap-webpack-plugin","last_synced_at":"2026-05-03T04:33:37.808Z","repository":{"id":211395107,"uuid":"728979492","full_name":"janghye0k/generate-sitemap-webpack-plugin","owner":"janghye0k","description":"Webpack plugin to generate a sitemap.","archived":false,"fork":false,"pushed_at":"2023-12-28T02:15:26.000Z","size":363,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-08T16:46:56.384Z","etag":null,"topics":["sitemap","sitemap-generator","webpack","webpack-plugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/janghye0k.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-12-08T05:57:49.000Z","updated_at":"2024-09-06T07:21:00.000Z","dependencies_parsed_at":"2023-12-18T00:49:24.738Z","dependency_job_id":"a6219313-4475-49d4-ac60-801605b701f3","html_url":"https://github.com/janghye0k/generate-sitemap-webpack-plugin","commit_stats":null,"previous_names":["d0orhyeok/generate-sitemap-webpack-plugin","d0orhyeok/sitemap-generator-webpack-plugin","janghye0k/generate-sitemap-webpack-plugin"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janghye0k%2Fgenerate-sitemap-webpack-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janghye0k%2Fgenerate-sitemap-webpack-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janghye0k%2Fgenerate-sitemap-webpack-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janghye0k%2Fgenerate-sitemap-webpack-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/janghye0k","download_url":"https://codeload.github.com/janghye0k/generate-sitemap-webpack-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246429447,"owners_count":20775806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["sitemap","sitemap-generator","webpack","webpack-plugin"],"created_at":"2024-12-13T06:07:03.712Z","updated_at":"2026-05-03T04:33:32.789Z","avatar_url":"https://github.com/janghye0k.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/webpack/webpack\"\u003e\n    \u003cimg width=\"200\" height=\"200\"\n      src=\"https://webpack.js.org/assets/icon-square-big.svg\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n[![npm][npm]][npm-url]\n[![node][node]][node-url]\n[![install size](https://packagephobia.com/badge?p=generate-sitemap-webpack-plugin)](https://packagephobia.com/result?p=generate-sitemap-webpack-plugin)\n\n# generate-sitemap-webpack-plugin\n\nWebpack plugin to generate a sitemap.\n\n## Getting Started\n\nTo begin, you'll need to install generate-sitemap-webpack-plugin:\n\n```shell\nnpm install generate-sitemap-webpack-plugin --save-dev\n```\n\n```shell\nyarn add -D generate-sitemap-webpack-plugin\n```\n\n```shell\npnpm add -D generate-sitemap-webpack-plugin\n```\n\nThen add the plugin to your webpack config. For example:\n\n**webpack.config.js**\n\n```javascript\nconst SitemapPlugin = require('generate-sitemap-webpack-plugin');\n\nmodule.exports = {\n  plugins: [new SitemapPlugin({ baseURL: 'https://your.website' })],\n};\n```\n\n**sitemap.xml**\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003curlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\u003e\n  \u003curl\u003e\n    \u003cloc\u003ehttps://your.website/index.html\u003c/loc\u003e\n  \u003c/url\u003e\n\u003c/urlset\u003e\n```\n\n\u003e **Note**\n\u003e\n\u003e `generate-sitemap-webpack-plugin` is to use files that already exist in the source tree, as part of the build process.\n\n\u003e **Note**\n\u003e\n\u003e If you want to add custom locations for sitemap.xml, you can use urls options\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n## Usage\n\nThe plugin's signature:\n\n**webpack.config.js**\n\n```javascript\nconst SitemapPlugin = require('generate-sitemap-webpack-plugin');\n\nmodule.exports = {\n  plugins: [new SitemapPlugin({ baseURL, urls, emitted, chunk, options })],\n};\n```\n\n- **[`baseURL`](#baseURL)**\n- **[`urls`](#urls)**\n- **[`emitted`](#emitted)**\n- **[`chunk`](#chunk)**\n- **[`options`](#options)**\n\n\u003cbr/\u003e\n\n### `baseURL` \u003csmall\u003e(required)\u003c/small\u003e\n\nRoot URL of your site (e.g. https://your.website)\n\nType: `string`\n\n\u003cbr/\u003e\n\n### `urls`\n\nOptional array of locations on your site. These can be strings or you can provide object to customize each url.\n\nType:\n\n```typescript\ntype urls = Array\u003cstring | SitemapURL\u003e;\n\ntype SitemapURL = {\n  loc: string;\n  lastmod?: string;\n  priority?: number;\n  changefreq?: Changefreq;\n};\n```\n\n\u003e **Note**\n\u003e\n\u003e If you provide the object in array, the following attributes may be set on each path object.\n\n| Name                 | Type     | Default     | Description                                                                                                                                                                                                     |\n| -------------------- | -------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `loc`\u003cbr/\u003e(required) | `string` | N/A         | URL of the page (e.g. some/link). Sum of this value and baseURL must be less than 2,048 characters.                                                                                                             |\n| `lastmod`            | `string` | `undefined` | The date of last modification of the page (e.g. 2023-12-08). This date should be in W3C Datetime format. This format allows you to omit the time portion, if desired, and use YYYY-MM-DD.                       |\n| `priority`           | `number` | `undefined` | The priority of this URL relative to other URLs on your site. Valid values range from 0.0 to 1.0.                                                                                                               |\n| `changefreq`         | `string` | `undefined` | How frequently the page is likely to change. List of applicable values based on [sitemaps.org](https://www.sitemaps.org/protocol.html):\u003cbr/\u003e`always`, `hourly`, `daily`, `weekly`, `monthly`, `yearly`, `never` |\n\n\u003cbr/\u003e\n\n### `emitted`\n\nOptional object to customize each url by webpack emitted assets. If you set to boolean `true`, the emitted all `.html` file being used\n\n- **[`callback`](#callback)**\n- **[`pattern`](#pattern)**\n\n#### `callback`\n\nCallback function for use emitted asset filename\n\nType:\n\n```typescript\ntype callback = (\n  location: string\n) =\u003e Omit\u003cSitemapURL, 'loc'\u003e | undefined | null;\n```\n\n\u003csmall\u003e\n\n- **[sitemapURL](#urls)**\n\n\u003c/small\u003e\n\nDefault: `N/A`\n\n#### `pattern`\n\nSpecific pattern to filter the asset (e.g. .html), This can be string (glob pattern) or you can provide function instead of string pattern\n\nType:\n\n```typescript\ntype pattern = string | ((asset: string) =\u003e boolean) | undefined;\n```\n\nDefault: `**/*.html`\n\n\u003e Note\n\u003e\n\u003e `pattern` use glob pattern to filter asset.\n\u003e For more information, follow the links below\n\u003e\n\u003e - [Glob Pattern Reference | Visual Studio Code](https://code.visualstudio.com/docs/editor/glob-patterns)\n\u003e - [Featrues | minimatch](https://github.com/isaacs/minimatch#features)\n\n\u003cbr/\u003e\n\n### `chunk`\n\nOptional object to customize each url by webpack chunk. You can use auxiliary files to make sitemap include image\n\n- **[`callback`](#callback)**\n- **[`img`](#pattern)**\n\n#### `callback`\n\nCallback function for use chunk\n\nType \u003csmall\u003e(Required)\u003c/small\u003e :\n\n```typescript\ntype callback = (\n  name: string,\n  hash: string\n) =\u003e SitemapURL | string | undefined | null;\n```\n\nDefault: `N/A`\n\n#### `img`\n\nOptions for add image locations\n\nType: `boolean`\n\nDefault: `true`\n\n\u003e Note\n\u003e\n\u003e If you provide `options.chunk.img = true` each url automatically contains auxiliary files which image extension is matched\n\u003e `imageExtList = [apng, avif, gif, jpg, jpeg, jfif, pjpeg, pjp, png, svg, webp, bmp, ico, cur, tif, tiff]`\n\n\u003cbr/\u003e\n\n### `options`\n\nOptional object of configuration settings.\n\n| Name         | Type                 | Default       | Description                                                                                                                                         |\n| ------------ | -------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `filename`   | `string`             | `sitemap.xml` | Name of the sitemap file emitted to your build output                                                                                               |\n| `format`     | `boolean`            | `false`       | Settings for format sitemap file. You can provide formatting options for write file prettier                                                        |\n| `gzip`       | `boolean`            | `true`        | Generating a gzipped `.xml.gz` sitemap. You can provide false to skip generating a gzipped. By default, both xml files are generated                |\n| `lastmod`    | `string` / `boolean` | `false`       | The date for \u003clastmod\u003e on all urls. Can be overridden by url-specific lastmod config. If value is true, the current date will be used for all urls. |\n| `priority`   | `number`             | `undefined`   | A \u003cpriority\u003e to be set globally on all locations. Can be overridden by url-specific priorty config.0.                                               |\n| `changefreq` | `string`             | `undefined`   | A \u003cchangefreq\u003e to be set globally on all locations. Can be overridden by url-specific changefreq config.                                            |\n\n[npm]: https://img.shields.io/npm/v/generate-sitemap-webpack-plugin.svg\n[npm-url]: https://www.npmjs.com/package/generate-sitemap-webpack-plugin\n[node]: https://img.shields.io/node/v/generate-sitemap-webpack-plugin.svg\n[node-url]: https://nodejs.org\n[size]: https://packagephobia.now.sh/badge?p=generate-sitemap-webpack-plugin\n[size-url]: https://packagephobia.now.sh/result?p=generate-sitemap-webpack-plugin\n\n## Examples\n\n### 1. Complex Example\n\n**webpack.config.js**\n\n```javascript\nconst path = require('path');\nconst HtmlWebpackPlugin = require('html-webpack-plugin');\nconst SitemapPlugin = require('generate-sitemap-webpack-plugin');\n\nconst entries = ['index', 'help', 'ejs'];\nconst entry = {};\nconst views = [];\nentries.forEach((name) =\u003e {\n  entry[name] = path.resolve(__dirname, `src/js/${name}.js`);\n\n  const htmlPlugin = new HtmlWebpackPlugin({\n    chunks: [name],\n    minify: false,\n    filename: `${name}.${name.includes('ejs') ? 'ejs' : 'html'}`,\n    template: path.resolve(__dirname, `src/views/${name}.ejs`),\n  });\n\n  views.push(htmlPlugin);\n});\n\nmodule.exports = {\n  mode: 'production',\n  entry: {\n    index: path.resolve(__dirname, 'path/to/index.js')\n    entry: path.resolve(__dirname, 'path/to/entry.js')\n    ejs: path.resolve(__dirname, 'path/to/ejs.js')\n  },\n  output: {\n    path: path.resolve(__dirname, 'dist'),\n    filename: 'js/[name].js',\n  },\n  plugins: [\n    new SitemapPlugin({\n      baseURL: 'https://your.website',\n      emitted: {\n        callback: (location) =\u003e ({\n          priority: location.includes('index') ? 1 : undefined,\n          changefreq: 'yearly',\n        }),\n        pattern: `**/*.{html,ejs}`,\n      },\n      urls: [\n        'first',\n        { loc: 'second.html', lastmod: '2023-12-19', priority: 0.3 },\n      ],\n      options: {\n        filename: 'my-sitemap.xml',\n        format: true, // default: false\n        gzip: true // default: true\n        changefreq: 'monthly',\n        lastmod: true,\n        priority: 0.6,\n      },\n    }),\n    new HtmlWebpackPlugin({\n      chunks: ['index'],\n      filename: 'index.html',\n      template: path.resolve(__dirname, 'path/to/index.html'),\n    }),\n    new HtmlWebpackPlugin({\n      chunks: ['entry'],\n      filename: 'entry.html',\n      template: path.resolve(__dirname, 'path/to/entry.html'),\n    }),\n    new HtmlWebpackPlugin({\n      chunks: ['ejs'],\n      filename: 'ejs.ejs',\n      template: path.resolve(__dirname, 'path/to/ejs.html'),\n    }),\n  ],\n};\n```\n\n**my-sitemap.xml**\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003curlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\u003e\n  \u003curl\u003e\n    \u003cloc\u003ehttps://your.website/index.html\u003c/loc\u003e\n    \u003clastmod\u003e2023-12-19T03:29:51.291Z\u003c/lastmod\u003e\n    \u003cchangefreq\u003eyearly\u003c/changefreq\u003e\n    \u003cpriority\u003e1\u003c/priority\u003e\n  \u003c/url\u003e\n  \u003curl\u003e\n    \u003cloc\u003ehttps://your.website/first\u003c/loc\u003e\n    \u003clastmod\u003e2023-12-19T03:29:51.291Z\u003c/lastmod\u003e\n    \u003cchangefreq\u003emonthly\u003c/changefreq\u003e\n    \u003cpriority\u003e0.6\u003c/priority\u003e\n  \u003c/url\u003e\n  \u003curl\u003e\n    \u003cloc\u003ehttps://your.website/entry.html\u003c/loc\u003e\n    \u003clastmod\u003e2023-12-19T03:29:51.291Z\u003c/lastmod\u003e\n    \u003cchangefreq\u003eyearly\u003c/changefreq\u003e\n  \u003c/url\u003e\n  \u003curl\u003e\n    \u003cloc\u003ehttps://your.website/ejs.ejs\u003c/loc\u003e\n    \u003clastmod\u003e2023-12-19T03:29:51.291Z\u003c/lastmod\u003e\n    \u003cchangefreq\u003eyearly\u003c/changefreq\u003e\n  \u003c/url\u003e\n  \u003curl\u003e\n    \u003cloc\u003ehttps://your.website/second.html\u003c/loc\u003e\n    \u003clastmod\u003e2023-12-19\u003c/lastmod\u003e\n    \u003cchangefreq\u003emonthly\u003c/changefreq\u003e\n    \u003cpriority\u003e0.3\u003c/priority\u003e\n  \u003c/url\u003e\n\u003c/urlset\u003e\n```\n\n### 2. Split Example\n\n**webpack.config.js**\n\n```javascript\nconst SitemapPlugin = require('generate-sitemap-webpack-plugin');\n\nmodule.exports = {\n  // Some webpack config\n  ...,\n  plugins: [\n    new SitemapPlugin({\n      baseURL: 'https://your.website',\n      urls: Array.from({ length: 150000 }, (_, i) =\u003e ({\n        loc: `${i}.html`,\n        lastmod:\n          i \u003c 50000 ? `2023-12-19` : undefined,\n      })),\n      options: {\n        format: true\n      }\n    }),\n  ],\n};\n```\n\n**sitemap.xml**\n\n```xml\n\u003c?xml version=\"1\" encoding=\"UTF-8\"?\u003e\n\u003csitemapindex\u003e\n  \u003csitemap\u003e\n    \u003cloc\u003ehttps://your.website/sitemap1.xml\u003c/loc\u003e\n    \u003clastmod\u003e2023-12-19\u003c/lastmod\u003e\n  \u003c/sitemap\u003e\n  \u003csitemap\u003e\n    \u003cloc\u003ehttps://your.website/sitemap2.xml\u003c/loc\u003e\n  \u003c/sitemap\u003e\n  \u003csitemap\u003e\n    \u003cloc\u003ehttps://your.website/sitemap3.xml\u003c/loc\u003e\n  \u003c/sitemap\u003e\n\u003c/sitemapindex\u003e\n```\n\n**sitemap1.xml**\n\n```xml\n\u003c?xml version=\"1\" encoding=\"UTF-8\"?\u003e\n\u003curlset\u003e\n  \u003curl\u003e\n    \u003cloc\u003ehttps://your.website/0.html\u003c/loc\u003e\n    \u003clastmod\u003e2023-12-19\u003c/lastmod\u003e\n  \u003c/url\u003e\n  \u003curl\u003e\n    \u003cloc\u003ehttps://your.website/1.html\u003c/loc\u003e\n    \u003clastmod\u003e2023-12-19\u003c/lastmod\u003e\n  \u003c/url\u003e\n  ... 49,998 items\n\u003c/urlset\u003e\n```\n\n### 3. Chunk Example\n\n**webpack.config.js**\n\n```javascript\nconst SitemapPlugin = require('generate-sitemap-webpack-plugin');\n\nmodule.exports = {\n  // Some webpack config\n  ...,\n  entry: {\n    index: 'path/to/index.js'\n    skip: 'path/to/skip.js'\n  },\n  module: {\n    rules: [\n      {\n        test: /\\.(?:jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$/i,\n        type: 'asset/resource',\n        generator: {\n          filename: 'assets/[name]-[hash][ext]',\n        },\n      },\n    ],\n  },\n  plugins: [\n    new SitemapPlugin({\n      baseURL: 'https://your.website',\n      chunk: {\n        callback: (name) =\u003e (name === 'skip' ? null : name + '.html'),\n      },\n      emitted: false,\n      options: {\n        format: true,\n      },\n    }),\n  ],\n};\n```\n\n**index.js**\n\n```javascript\nimport Sample from 'path/to/asset/sample.png';\nimport Move from 'path/to/asset/move.gif';\n\n... some scripts\n```\n\n**sitemap.xml**\n\n```xml\n\u003c?xml version=\"1\" encoding=\"UTF-8\"?\u003e\n\u003curlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\"\u003e\n  \u003curl\u003e\n    \u003cloc\u003ehttps://your.website/index.html\u003c/loc\u003e\n    \u003cimage:image\u003e\n      \u003cimage:loc\u003ehttps://your.website/assets/move-31d6cfe0d16ae931b73c.gif\u003c/image:loc\u003e\n    \u003c/image:image\u003e\n    \u003cimage:image\u003e\n      \u003cimage:loc\u003ehttps://your.website/assets/sample-31d6cfe0d16ae931b73c.png\u003c/image:loc\u003e\n    \u003c/image:image\u003e\n  \u003c/url\u003e\n\u003c/urlset\u003e\n\n```\n\n## License\n\n[MIT](./LICENSE)\n\n[npm]: https://img.shields.io/npm/v/generate-sitemap-webpack-plugin.svg\n[npm-url]: https://npmjs.com/package/generate-sitemap-webpack-plugin\n[node]: https://img.shields.io/node/v/generate-sitemap-webpack-plugin.svg\n[node-url]: https://nodejs.org\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanghye0k%2Fgenerate-sitemap-webpack-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjanghye0k%2Fgenerate-sitemap-webpack-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanghye0k%2Fgenerate-sitemap-webpack-plugin/lists"}