absolutize-css-resources
Converts the links of all css images, fonts and other resources into absolute paths from a css file, and you are free to worry about improper replacement.
Install
$ npm install absolutize-css-resources --save
Usage
var absolutize = ;var url = ; ;
If we have a css file:
Then the parsed_content
will be:
absolutize(file_content, options, callback [, callback_on_found])
- file_content
String
the content of the css file - options
Object
- filename
path
the absolute path of the css file - filebase
path
- resolve
function(relative_path)
the method to resolve therelative_path
to an absolute url- relative_path the path of each css image or resource which is relative to
filebase
- relative_path the path of each css image or resource which is relative to
- allow_absolute_url
Boolean=true
whether allow absolute url of css images, such asbackground: url(/a.png)
which is a bad practice.
- filename
- callback
function()
the error(if exists) and the parsed content will pass to the callback function. - callback_on_found
function(path, relative_path)=
called if a css resource is found. Optional.- path the original pathname of the resource
- relative_path the pathname relative to the
filebase
options.resolve(relative_path)
options.resolve
can be a synchronous method or an asynchronous one by using the common this.async()
style.
Sometimes, we need to invoke an asynchronous process to fetch the version info of a image, querying version from db or digesting md5 from the file content, for example.
// options { // Turns the method into an async method var done = this; ; }
License
MIT