GithubHelp home page GithubHelp logo

dolymood / urify-emitter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mattdesl/urify-emitter

0.0 3.0 0.0 252 KB

[proof-of-concept] emits files instead of inlining datauri statements

License: MIT License

JavaScript 100.00%

urify-emitter's Introduction

urify-emitter

experimental

Similar to webpack's file-loader, this builds on the urify transform but emits a file into an application-level output directory. This allows for modular front-end code which relies on images and icons, without increasing JS bundle size or sacrificing browser image caching optimizations.

Example front-end code:

var datauri = require('datauri')
var uri = datauri(__dirname+'/icon.png')

var img = new Image()
img.onload = function() {
	console.log("Image loaded!")
}
img.src = uri

Now, from your application, you can bundle the code using the urify-emitter plugin.

browserify -p [ urify-emitter -o images ] index.js > bundle.js

This will emit a bundle.js file, which inlines the URI like so:

var uri = 'images/53cf2c1426533b467d606312b4e246ef.png'

It will also copy the static asset icon.png with the above hashed URL to your specified output directory, in this case images.

You can also specifiy a --limit (or -l) option, and if the file is under that size in bytes, it will be inlined as a regular data URI.

bundle-wide

The plugin only transforms source at the top-level (i.e. application). To transform all module code throughout a bundle, you will need browserify v.6.1.0+ and the --ignore-transform command to override all urify transforms:

browserify -p urify-emitter --it urify index.js > bundle.js

gulp, grunt, npm scripts

For a practical implementation of this, see urify-example.

Usage

NPM

  • --output, -o the output directory, defaults to .
  • --limit, -l the limit in bytes, under which we will inline with a Data URI
  • --base, -b an optional base to use on the inlined URL, which is joined with the asset name. For example, your local output directory might be in app/output, but your site URLs you can specify --base output so they look like output/53cf2c14265..png

License

MIT, see LICENSE.md for details.

urify-emitter's People

Contributors

mattdesl avatar

Watchers

James Cloos avatar doly mood avatar  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.