Skip to content

dgrammatiko/lightningcss-url-version

Repository files navigation

lightningcss-url-version

GitHub issues GitHub license

Twitter

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

Usage

install it:

npm i -D @dgrammatiko/lightningcss-plugin-url-version

Include it in your scripts:

import UrlVersion from '@dgrammatiko/lightningcss-plugin-url-version';

Use as any other lightningcss plugin:

const { code } = transform({
 minify: true,
 code: Buffer.from('...'),
 visitor: composeVisitors([urlVersioning({ from: 'the/path/to/the/current/file.css'})]),
});

Options

There are 4 options, version and variable, skipExternal and from:

  • version: a function that returns a string for the hash (NOT an arrow function!)
  • variable: could be a a string denoting the URLparam that will be used for the version
  • skipExternal: skip URLS from an external domain
  • from: the path to the current css file

eg:

import UrlVersion from 'lightningcss-plugin-url-version';

const { code } = transform({
 minify: true,
 code: Buffer.from('...'),
 visitor: composeVisitors([urlVersioning(opts)]),
});


// Will produce something like url(files/16761/star.gif?v=1614866396902);

License MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •