<commit_before># cdnizer

[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]

> cdnizer plugin for [gulp](https://github.com/wearefractal/gulp)

This plugin will replace local file references in HTML and other files with CDN locations.  This allows you to work with local copies of libraries during development, and then automate switching to your CDN version when you deploy your application.

For example, if you have a development file that looks like this:

```html
<html>
<head>
<script type="text/javascript" src="bower_components/angular/angular.js"></script>
…
```

You can use cdnizer to automatically convert it to this during your build process (*every* change here can be customized):

```js
<html>
<head>
<script>
function cdnizerLoad(u) {
	document.write('<scr'+'ipt src="'+encodeURIComponent(u)+'"></scr'+'ipt>';
}
</script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.min.js"></script>
<script>if(!(angular)) cdnizerLoad("bower_components/angular/angular.js");</script>
…
```

> ## WARNING
>
> This plugin does not check incoming files.  Do not run it on files that you do not want modified.


### Features:
* It's flexible without being overly complicated.
* Handles private *and* multiple public CDNs in the same build.
* It can use your bower installation to determine the correct file versions—no more getting "upgraded" during your build.
* Provides optional fallback scripts for failed file loading. (By default it can only handle failed JavaScript files, but it's easy to provide a custom solution.)


### New in version 1.0

cdnizer now can load CDN data from existing `*-cdn-data` packages, currently `google-cdn-data`, `cdnjs-cdn-data`, and `jsdelivr-cdn-data`.  Now you can [configure common public CDNs with a single line](#optionsfilescommon-cdn)!


### Possible breaking change in 1.0

The `version` field has been changed in this release.  Previously, it was the exact version as it existing within bower.  Now, `version` is the string `major(.minor)?(.patch)?`, with any trailing (`-beta*`, `-snapshot*`, etc) information removed.  (Alpha-numeric characters that are attached to the version string, as in `1.0.0rc1`, are not stripped.)

You can still access the full version string via `versionFull`, which is not modified at all.



## Index

* [Usage](#usage)
* [API](#api)
* [Support This Project](#help-support-this-project)
* [License](#license)



## Usage

First, install `gulp-cdnizer` as a development dependency:

```shell
npm install --save-dev gulp-cdnizer
```

Then, add it to your `gulpfile.js`:

```javascript

var cdnizer = require("gulp-cdnizer");

gulp.src("./src/index.html")
        .pipe(cdnizer({
            defaultBase: "//my.cdn.host/base",
            allowRev: true,
            allowMin: true,
            files: [
                             
				// This file is on the default CDN, and will replaced with //my.cdn.host/base/js/app.js
				'js/app.js',
				
				// On Google's public CDN
				{
					file: 'vendor/angular/angular.js',
					package: 'angular',
					test: 'angular',
					cdn: '//ajax.googleapis.com/ajax/libs/angularjs/${ version }/angular.min.js'
				},
				
				// On Firebase's public CDN
				{
					file: 'vendor/firebase/firebase.js',
					test: 'Firebase',
					cdn: '//cdn.firebase.com/v0/firebase.js'
				}
			]
        }))
        .pipe(gulp.dest("./dist"));
```
     
Alternatively, you can just pass in the files array if you don't need to provide any options, and only have custom files:

```js

gulp.src("./src/index.html")
        .pipe(cdnizer([
            {
                file: 'vendor/angular/angular.js',
                package: 'angular',
                test: 'angular',
                // use altnerate providers easily
                cdn: '//cdnjs.cloudflare.com/ajax/libs/angularjs/${ version }/angular.min.js'
            },
            {
                file: 'vendor/firebase/firebase.js',
                test: 'Firebase',
                cdn: '//cdn.firebase.com/v0/firebase.js'
            }
        ]))
        .pipe(gulp.dest("./dist"));
```

You can also use globs to define groups of file, and dynamic filename properties:

```js
gulp.src("./src/index.html")
        .pipe(cdnizer([{
                file: 'vendor/angular/*.js',
                package: 'angular',
                test: 'angular',
                cdn: '//ajax.googleapis.com/ajax/libs/angularjs/${ version }/${ filenameMin }'
            }]))
        .pipe(gulp.dest("./dist"));
```

**New in v1.0**, you can use simplified strings for common public CDNs, like so:

```js
gulp.src("./src/index.html")
        .pipe(cdnizer([{
				'google:angular',          // for most libraries, that's all you'll need to do!
				'cdnjs:jquery',
				{
					cdn: 'jsdelivr:yui',   // You can also use a known CDN, while…
					package: 'yui3',       // overriding the package name for bower, and…
					test: 'YUI'            // providing a custom fallback test
				}
            }]))
        .pipe(gulp.dest("./dist"));
```

Works great on `url()`s in CSS files, too:

```js

gulp.src("./src/css/style.css")
        .pipe(cdnizer({
            defaultCDNBase: '//my.cdn.url/',
            relativeRoot: 'css',
            files: ['**/*.{gif,png,jpg,jpeg}']
        }))
        .pipe(gulp.dest("./dist/css/"));
```



## API

* [cdnizer( options | files )](#cdnizer-options--files-)
* Shared Options
    * [defaultCDNBase](#optionsdefaultcdnbase)
	* [defaultCDN](#optionsdefaultcdn)
	* [relativeRoot](#optionsrelativeroot)<commit_msg>Modified docs<commit_after># cdnizer

[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]

> cdnizer plugin for [gulp](https://github.com/wearefractal/gulp)

This plugin will replace local file references in HTML and other files with CDN locations.  This allows you to work with local copies of libraries during development, and then automate switching to your CDN version when you deploy your application.

For example, if you have a development file that looks like this:

```html
<html>
<head>
<script type="text/javascript" src="bower_components/angular/angular.js"></script>
…
```

You can use cdnizer to automatically convert it to this during your build process (*every* change here can be customized):

```js
<html>
<head>
<script>
function cdnizerLoad(u) {
	document.write('<scr'+'ipt src="'+encodeURIComponent(u)+'"></scr'+'ipt>';
}
</script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.min.js"></script>
<script>if(!(angular)) cdnizerLoad("bower_components/angular/angular.js");</script>
…
```


### Features:
* It's flexible without being overly complicated.
* Handles private *and* multiple public CDNs in the same build.
* It can use your bower installation to determine the correct file versions—no more getting "upgraded" during your build.
* Provides optional fallback scripts for failed file loading. (By default it can only handle failed JavaScript files, but it's easy to provide a custom solution.)

> ## WARNING
>
> This plugin does not check incoming files.  Do not run it on files that you do not want modified.


### New in version 1.0

cdnizer now can load CDN data from existing `*-cdn-data` packages, currently `google-cdn-data`, `cdnjs-cdn-data`, and `jsdelivr-cdn-data`.  Now you can [configure common public CDNs with a single line](#optionsfilescommon-cdn)!


### Possible breaking change in 1.0

The `version` field has been changed in this release.  Previously, it was the exact version as it existing within bower.  Now, `version` is the string `major(.minor)?(.patch)?`, with any trailing (`-beta*`, `-snapshot*`, etc) information removed.  (Alpha-numeric characters that are attached to the version string, as in `1.0.0rc1`, are not stripped.)

You can still access the full version string via `versionFull`, which is not modified at all.



## Index

* [Usage](#usage)
* [API](#api)
* [Support This Project](#help-support-this-project)
* [License](#license)



## Usage

First, install `gulp-cdnizer` as a development dependency:

```shell
npm install --save-dev gulp-cdnizer
```

Then, add it to your `gulpfile.js`:

```javascript
var cdnizer = require("gulp-cdnizer");

gulp.src("./src/index.html")
        .pipe(cdnizer({
            defaultBase: "//my.cdn.host/base",
            allowRev: true,
            allowMin: true,
            files: [
                             
				// This file is on the default CDN, and will replaced with //my.cdn.host/base/js/app.js
				'js/app.js',
				
				// On Google's public CDN
				{
					file: 'vendor/angular/angular.js',
					package: 'angular',
					test: 'angular',
					cdn: '//ajax.googleapis.com/ajax/libs/angularjs/${ version }/angular.min.js'
				},
				
				// On Firebase's public CDN
				{
					file: 'vendor/firebase/firebase.js',
					test: 'Firebase',
					cdn: '//cdn.firebase.com/v0/firebase.js'
				}
			]
        }))
        .pipe(gulp.dest("./dist"));
```
     
Alternatively, you can just pass in the files array if you don't need to provide any options, and only have custom files:

```js
gulp.src("./src/index.html")
        .pipe(cdnizer([
            {
                file: 'vendor/angular/angular.js',
                package: 'angular',
                test: 'angular',
                // use altnerate providers easily
                cdn: '//cdnjs.cloudflare.com/ajax/libs/angularjs/${ version }/angular.min.js'
            },
            {
                file: 'vendor/firebase/firebase.js',
                test: 'Firebase',
                cdn: '//cdn.firebase.com/v0/firebase.js'
            }
        ]))
        .pipe(gulp.dest("./dist"));
```

You can also use globs to define groups of file, and dynamic filename properties:

```js
gulp.src("./src/index.html")
        .pipe(cdnizer([{
                file: 'vendor/angular/*.js',
                package: 'angular',
                test: 'angular',
                cdn: '//ajax.googleapis.com/ajax/libs/angularjs/${ version }/${ filenameMin }'
            }]))
        .pipe(gulp.dest("./dist"));
```

**New in v1.0**, you can use simplified strings for common public CDNs, like so:

```js
gulp.src("./src/index.html")
        .pipe(cdnizer([
				'google:angular',          // for most libraries, that's all you'll need to do!
				'cdnjs:jquery',
				{
					cdn: 'jsdelivr:yui',   // You can also use a known CDN, while…
					package: 'yui3',       // overriding the package name for bower, and…
					test: 'YUI'            // providing a custom fallback test
				}
            ]))
        .pipe(gulp.dest("./dist"));
```

Works great on `url()`s in CSS files, too:

```js
gulp.src("./src/css/style.css")
        .pipe(cdnizer({
            defaultCDNBase: '//my.cdn.url/',
            relativeRoot: 'css',
            files: ['**/*.{gif,png,jpg,jpeg}']
        }))
        .pipe(gulp.dest("./dist/css/"));
```



## API

* [cdnizer( options | files )](#cdnizer-options--files-)
* Shared Options
    * [defaultCDNBase](#optionsdefaultcdnbase)
	* [defaultCDN](#optionsdefaultcdn)
	* [relativeRoot](#optionsrelativeroot)
{'fraction_non_alphanumeric': 0.14571556751906684, 'fraction_numerical': 0.003050695379093764, 'mean_word_length': 2.721535893155259, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 39, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '584635', 'n_tokens_mistral': 3769, 'n_tokens_neox': 3367, 'n_words': 1036}