Code Monkey home page Code Monkey logo

gulp-microfill's Introduction

gulp-microfill

Only loads polyfills for the missing gabs

How to install

1. Install gulp CLI
npm install --global gulp
2. Install gulp as a project dependency
npm install gulp --save-dev
3. Install gulp-microfill
npm install gulp-microfill --save-dev

How to use

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

gulp.task('default', function() {
	gulp.src('lib/**/*.js')
		.pipe(microfill(['set-immediate', 'promise', 'fetch', 'collection']))
		.pipe(gulp.dest('release'))
});

Options

gulp-microfill takes two arguments, an array with the polyfills and optionally an option object. See microfill for a complete list of all supported polyfills.

The option object may contain:

  • minified (boolean) - Use a minified loader and minified polyfills (if available)
  • fileName (string or function) - The filename used in the loader. This should be relative to the base url of your webpage. If you specify a function, it will be invoked for every file and should return the fileName as a string.

How does it work

Microfill replaces your javascript file with a file that looks like this:

;(function(){
	var hex = 0;

	if (!window.setImmediate) hex += 1 << 0;
	if (!window.Promise) hex += 1 << 1;
	if (!window.fetch) hex += 1 << 2;
	if (!window.WeakMap || !window.Map || !window.Set) hex += 1 << 3;

	var script = document.createElement("script");
	script.src = "file-" + hex.toString(16) + ".js";
	script.type = "text/javascript";
	document.head.appendChild(script);
})();

If a feature is missing, hex will be increased by a certain value. Based on the final value of hex a file will be loaded. Microfill generates such file for every possible combination of polyfills that are needed. See the test directory for a sample output.

License

MIT

gulp-microfill's People

Contributors

ivogabe avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.