Socket
Socket
Sign inDemoInstall

sitemap-webpack-plugin

Package Overview
Dependencies
18
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    sitemap-webpack-plugin

Webpack plugin to generate a sitemap.


Version published
Weekly downloads
9.6K
decreased by-2.46%
Maintainers
1
Install size
3.42 MB
Created
Weekly downloads
 

Changelog

Source

1.1.1

  • Fix for webpack 4 pre-4.40 not having compilation.emitAsset

1.1

  • Plugin source is now TypeScript and type declaration files are included when installed from npm

1.0

  • First stable release! :tada:
  • Plugin now accepts a single options object to match the webpack convention.
  • Added schema validation for plugin configuration.
  • Dropped support for deprecated camel-cased option names. "changefreq", "filename", "lastmod", and "skipgzip" must now be lowercase.
  • To upgrade from 0.x: 1) change the plugin arguments to a single object as detailed below, and 2) downcase any camel-cased option names as mentioned in the previous bullet.
// Before:
{
  // snip
  plugins: [
    new SitemapPlugin(
      'https://mysite.com',
      [
        {
          path: '/foo/',
          lastMod: '2015-01-04',
          priority: '0.8',
          changeFreq: 'daily'
        },
        {
          path: '/bar/',
        }
      ],
      {
        fileName: 'map.xml',
        lastMod: true,
        changeFreq: 'monthly',
        priority: '0.4'
      }
    )
  ]
}

// After:
{
  // snip
  plugins: [
    new SitemapPlugin({
      base: 'https://mysite.com',
      paths: [
        {
          path: '/foo/',
          lastmod: '2015-01-04',
          priority: 0.8,
          changefreq: 'daily'
        },
        {
          path: '/bar/',
        }
      ],
      options: {
        filename: 'map.xml',
        lastmod: true,
        changefreq: 'monthly',
        priority: 0.4
      }
    })
  ]
}

Readme

Source

npm version CircleCI Coverage Status

sitemap-webpack-plugin

Webpack plugin to generate a sitemap from a list of paths.

Installation

npm install sitemap-webpack-plugin --save-dev

For webpack 4 or 5, use the latest version. For webpack <= 3, use version 0.5.x.

Usage

Add to your webpack config -- see below for examples. The plugin signature is:

new SitemapPlugin({ base, paths, options })
  • base is the root URL of your site (e.g. https://mysite.com)
  • paths is the array of locations on your site. These can be simple strings or you can provide objects if you would like to customize each entry; objects must have a path attribute and may have other attributes documented below.
  • options is an optional object of top-level configuration settings.

Options

The following options may be provided in the options argument to the plugin constructor. This library uses the sitemap package under the hood, so you can also provide any other options that sitemap supports.

NameTypeDefaultDescription
filenamestringsitemap.xmlName of the sitemap file emitted to your build output
skipgzipbooleanfalseWhether to skip generating a gzipped .xml.gz sitemap. (By default, both an uncompressed and a compressed sitemap are generated -- the compressed version is generated at sitemap.xml.gz, or [filename].gz if the filename configuration option is set.)
formatterfunctionundefinedAn optional function to format the generated sitemap before it is emitted (for example, if you'd like to pretty-print the XML). The provided function must accept one argument (the unformatted XML) and return the formatted XML as a string. For an example of pretty-printing configuration, see the formatted test.
lastmodstring / booleanfalseThe date value for <lastmod> on all paths. Can be overridden by path-specific lastmod setting. If set to boolean true, the current date will be used for all paths; otherwise, the provided date string will be used.
prioritynumberundefinedA <priority> to be set globally on all locations. Can be overridden by path-specific priority.
changefreqstringundefinedA <changefreq> to be set globally on all locations; list of applicable values based on sitemaps.org: always, hourly, daily, weekly, monthly, yearly, never. Can be overridden by path-specific changefreq.

Path-specific options

If you choose to provide the paths as an array of objects, the following attributes may be set on each path object. This library uses the sitemap package under the hood, so you can also provide any other options that sitemap supports.

NameTypeDefaultDescription
path (required)stringN/AThe URL path, e.g. /some/page
lastmodstringfalseThe date value for <lastmod> -- when this path was last modified.
prioritynumberundefinedA numerical <priority> to be set on the path.
changefreqstringundefinedThe <changefreq> to be set on the path; list of applicable values based on sitemaps.org: always, hourly, daily, weekly, monthly, yearly, never.

Example webpack.config.js

const SitemapPlugin = require('sitemap-webpack-plugin').default;

// Example of simple string paths
const paths = [
  '/foo/',
  '/bar/'
];

// Example of object paths
// Object paths must have a `path` attribute -- others are optional,
// and fall back to global config (if any)
const paths = [
  {
    path: '/foo/',
    lastmod: '2015-01-04',
    priority: 0.8,
    changefreq: 'monthly'
  },
  {
    path: '/bar/',
    lastmod: '2018-02-05',
    priority: 0.5,
    changefreq: 'yearly'
  }
];

// Example webpack configuration -- input/output/etc. omitted for brevity.
export default {
  // Basic usage (output defaults to sitemap.xml)
  plugins: [
    new SitemapPlugin({ base: 'https://mysite.com', paths })
  ]

  // With custom output filename
  plugins: [
    new SitemapPlugin({
      base: 'https://mysite.com',
      paths,
      options: {
        filename: 'map.xml'
      }
    })
  ]

  // Skip generating a gzipped version of the sitemap
  plugins: [
    new SitemapPlugin({
      base: 'https://mysite.com',
      paths,
      options: {
        skipgzip: true
      }
    })
  ]

  // With global options
  plugins: [
    new SitemapPlugin({
      base: 'https://mysite.com',
      paths,
      options: {
        filename: 'map.xml',
        lastmod: true,
        changefreq: 'monthly',
        priority: 0.4
      }
    })
  ]
};

Contributing

  1. Fork the repository (https://github.com/schneidmaster/sitemap-webpack-plugin/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new pull request

License

MIT

Keywords

FAQs

Last updated on 14 Jul 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc