cdnify

0.1.4 • Public • Published

cdnify

Simple library to easily switch between local and CDN libraries.

Installation

Just run

$ npm install -g cdnify

Usage

You just need to add the cdn attributes with the URL pointing to the CDN you want to get started.

For example, let say the following file is called index.html.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Foobar</title>
  <script src="js/foo.js" cdn="//mycdn.com/bar.js"></script> 
  <link href="css/foo.css" cdn="//mycdn.com/bar.css">
</head>
<body>
 
</body>
</html>

By running

$ cdnify index.html -o dist/index.html

You will get

  <script src="//mycdn.com/bar.js"></script> 
  <link href="//mycdn.com/bar.css">

in dist/index.html.

If you want to keep the local source, pass the --use-local flag.

Options

  • --output (aliased: -o): Set the output. Uses stdout if not set.
  • --use-local (default: false): Uses local file (set by src or href) instead of cdn
  • --incompatible (aliased: -i, default: []): Set a list of attributes incompatible with cdn. If used together, an error will return.
  • --cdn-attr (aliased: t, default: cdn): Set the attribute to be used for the CDN source.

Sample command:

$ cdnify -o foo.html --use-local -i glob -i other-attr --cdn-attr custom-attr

Public API

This module exposes two functions:

  • cdnify.process(rawHtml, options, callback) Arguments:

    • rawHtml: The raw HTML to process

    • options: The options as specified for the CLI. camelCase can be used instead of dash separated words.

    • callback: The callback to be called when done. The callback has the form:

      function (err, html, $) {
       
      }

      where html is the processed HTML as a string and $ is an instance of cheerio, in case more processing is needed.

  • cdnify.processFile(filepath, options, callback) Excatly the same function as above, except that the first argument is the path to the HTML file to proces, instead of the raw HTML.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.4
    18
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.4
    18
  • 0.1.3
    0
  • 0.1.2
    0
  • 0.1.1
    0
  • 0.1.0
    0

Package Sidebar

Install

npm i cdnify

Weekly Downloads

18

Version

0.1.4

License

MIT

Last publish

Collaborators

  • danhper