postcss-url-version

1.0.5 • Public • Published

postcss-url-version

GitHub issues GitHub license

Twitter

Postcss-url-version is a simple PostCSS plugin that adds a hash on every url property.

Usage

install it:

npm i -D postcss-url-version

Include it in your scripts:

const UrlVersion = require('postcss-url-version');

Use as any other PostCSS plugin:

Postcss([Autoprefixer, UrlVersion])...

Options

There are 2 options, version and variable:

  • version a function that returns a string for the hash
  • variable could be a a string denoting the URLparam that will be used for the version

eg:

const UrlVersion = require('postcss-url-version');
const versioned = UrlVersion({
  // The path of the asset relative to the css is passed as argument to the function,
  // so you can hash the content of the file for a better invalidation strategy
  version: (path) => new Date().valueOf().toString(),
  variable: 'v',
});
Postcss([versioned])...

// Will produce something like url("https://mdn.mozillademos.org/files/16761/star.gif?v=1614866396902");

License MIT

Package Sidebar

Install

npm i postcss-url-version

Weekly Downloads

6

Version

1.0.5

License

MIT

Unpacked Size

6.74 kB

Total Files

4

Last publish

Collaborators

  • dgrammatiko