GithubHelp home page GithubHelp logo

weisjohn / gulp-asset Goto Github PK

View Code? Open in Web Editor NEW

This project forked from inlight-media/gulp-asset

0.0 2.0 0.0 188 KB

Gulp module for managing asset revisions and using multiple domains to server assets.

License: MIT License

JavaScript 100.00%

gulp-asset's Introduction

gulp-asset

Gulp module for managing asset revisions and paths.

  • Define assets in all resources using 'asset://' prefix. These will be replaced with correct paths.
  • Adds revision hash using md5 hash of file contents
  • Load balance assets across domains
  • Use manifest file to access revision files within javascript
  • Assets always loaded from same domain
  • Detects broken asset urls during build process
  • Template engine agnostic

Creates revision using md5 hash of file contents and replaces all occurances of path in referencing files. Also allows you to prefix asset urls for balancing across cdn domains. It will also ensure that a single file only ever comes from the one prefix so assets aren't double downloaded.

Install

Install with npm

npm install --save-dev gulp-asset

Usage

var gulp = require('gulp');
var asset = require('gulp-asset');

asset.config({
	prefix: ['http://cdn1.google.com', 'http://cdn2.google.com']
});

gulp.task('js', function () {
	gulp.src('src/assets/js/**/*.js')
		.pipe(asset.rev())
		.pipe(asset.replace())
		.pipe(gulp.dest('dist/assets/js'));
});

Examples

Example JavaScript file

// You can explicitly use an asset:// string
var image = 'asset://img/image.png';
var font = 'asset://fonts/test.eot';

// Or construct a path and use the window.__assets variable
var key = 'asset://' + 'fonts/' + 'test' + '.eot';
var font = window.__assets[key];

Example HTML file

<img src="asset://img/image.png">

Example CSS file

body {
	background: blue url('asset://img/image.png');
}

License

MIT

gulp-asset's People

Watchers

John Weis avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.