1.0.1 • Published 5 months ago

@dgrammatiko/lightningcss-url-version v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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