wesber

0.4.0 • Public • Published

wesber

npm version Build Status Coverage Status

A simple web resource dependencies finder and replacer.

Why make this? When we try to build web static files, we should trace all of the resources which the page depends. Then need a tool to help find the dependencies and replace their url (using hash as placeholder), which is wesber.

Usage

API

const { css, html } = require('wesber')
 
css('style.css').then((result) => {
  ...
  // result = { file: ..., source: ..., replacer: ..., dependencies: [ ...] }
})
 
html('index.html', {
  resolved: [ 'script' ]
}).then((result) => {
  ... // result structure is the same, but just script tag.
})

Example

result:

result = {
    file: '/Users/boom/Github/wesber/test/files/style.css',
    source: '.icon-a{\nbackground: url(foo.png)no-repeat;\n}\n',
    replacer: '.icon-a{\nbackground: url(#b0b5895c)no-repeat;\n}',
    dependencies: [
        {
            file: 'foo.png',
            hash: '#b0b5895c',
            entireUri: false,
            base64: false,
            path: '/Users/boom/Github/wesber/test/files/foo.png',
            exists: false
        }
    ]
}

License

MIT

Package Sidebar

Install

npm i wesber

Weekly Downloads

0

Version

0.4.0

License

MIT

Last publish

Collaborators

  • teabyii