• Stars
    star
    6
  • Rank 2,532,503 (Top 51 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 10 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A better usemin

gulp-usemin-reloaded

A better usemin.

Why?

Once I've begun to develop using Gulp tasks and plugins, I've discovered that a lot of them are done in a really crappy way. The feature itself is cool but the code is unmanageable in the future. So, this is my effort to bring a better usemin with a cleaner logic and extensibility, but also proving a retrocompatibility layer with all existing usemin projects.

Features

  • Full UseMin compatible.
  • Extensible through callbacks (you do what you want with your own rules)
  • Extensible rules (why stick only with build:something when you can write myrule:context?)
  • Gulp Vinyl Stream compatible using gulp-through

How to install

npm install gulp-usemin-reloaded

Documentation

Rules

As you already know there are some standard rules that usemin tasks were using like build:css, build:js or build:remove. With this plugin we're going to extend those by using a more generic approach:

action:context outputPath [attributes]

where

  • action is the name of your own task (i.e. build)
  • context is the tag to recognize your task (i.e. css)
  • outputPath is where you want this to be saved, relative to your gulp.dest path (i.e. css/screen.css)
  • [attributes] are tha HTML attributes to append to the output tag that will be replaced (i.e. media="screen")

Callback

Usually usemin does everything out-of-the-box by itself, but since we're going to have custom Rules, we're also going to have custom callbacks to manage them. It's really simple to do that when you declare this plugin in your own gulpfile.js.

var usemin = require('gulp-usemin-reloaded');

.pipe(
    usemin({
        rules: {
            build: {
                css: [minifyCss(), 'concat'],
                js: [uglify(), rev()],
                html: [minifyHtml({empty: true})],
                remove: function( object, content ) {
                    return '';
                }
            }
        }
    })
)

In this case the remove task (aka context) is declared as a callback.

as INPUT parameters you have:

  • object is the parsed object of the current task rule (aka 'action`). It's a dictionary containing all the parsed HTML as a lookup dictionary.
  • content is the current evaluated content that can be manipulated directly from the callback.

as OUTPUT it expect the handled content, in this case an empty string (we want to discard everything that is between <!-- build:remove --> and <!-- endbuild -->. The replacement will be done ALWAYS by the plugin and not by you. So do NOT ever return the modified 'content' parameter. That is only a READ-ONLY var that you can use to base your decision (do 'if' or some other logical operators).

You can declare as many actions and contexts you like. Their value can be:

  • array of other tasks to be run
  • callback as described

Object

Of course the whole refactory is based on one logic. Every HTML tag is parsed as a dictionary and could be read and/or extend with different values. This is an example on how it will look like:

HTML

<!-- build:remove -->
<script src="js/null.js"></script>
<!-- endbuild -->

DICTIONARY

{
    action: 'build',
    context: 'remove',
    nodes: [
        {
            _tagName: 'script',
            src: 'js/null.js'
        }
    ],
    startTag: 'build: remove',
    endTag: 'endbuild',
    files: [
        // List of Vinyl INPUT Files ( src/href for each HTML tag )
    ]
}

License

See LICENSE file.

More Repositories

1

FFNx

Next generation modding platform for Final Fantasy VII and Final Fantasy VIII ( with native Steam 2013 release support! )
C++
340
star
2

LineageOTA

A simple OTA REST Server for LineageOS OTA Updater System Application
PHP
215
star
3

iPoPS

Convert your PSX Discs and ISOs into the PBP format, and play them on your PSP
C
60
star
4

gitbook-plugin-summary

Gitbook plugin to auto-generate SUMMARY.md
JavaScript
52
star
5

docker-powerdns

PowerDNS + Recursor + Admin GUI + Adblock in one single Docker
Shell
52
star
6

vps-powered-by-docker

Arch Linux setup script to obtain a full VPS with Automatic Reverse Proxy (and more) without pain
Shell
27
star
7

docker-woocommerce

PHP Docker for Woocommerce on Steroids
Dockerfile
22
star
8

docker-lineage-cicd

Docker microservice for LineageOS Continuous Integration and Continous Deployment
Dockerfile
17
star
9

PostEvent

A Cross-Domain Event Handler javascript library. Pure Vanilla JS, no dependencies.
HTML
15
star
10

sublime-projecttreetemplater

A simple templater for your project: manage the tree with a simple script!
Python
15
star
11

LineageOTAUnitTest

A LineageOS OTA Unit Test made for NodeJS
JavaScript
10
star
12

jvectormap-italy-provinces

A plugin for jVectorMap which includes an Italy Map with Provinces Areas
10
star
13

TwigPress

A boilerplate Twig Engine Theme for Wordpress
PHP
9
star
14

chrome-link-revealer

Simply reveal links when you hover your mouse over anchors
JavaScript
9
star
15

chrome-deezer-mediakeys-reloaded

Add multimedia keys support to Deezer
JavaScript
9
star
16

spotify-playlist-extractor

Bring back the freedom of choice to users. Let them export their playlist from Spotify, whenever they want :)
JavaScript
9
star
17

SteamworksSDKCI

CI builds of Steamworks SDK for CMake build systems
C++
9
star
18

docker-awesome-wordpress

A Docker that combines all the most awesome needed things for a powerful Wordpress installation
Dockerfile
8
star
19

chrome-spotify-mediakeys-reloaded

Add multimedia keys support to Spotify
JavaScript
6
star
20

Palmer

FF7 Field Background Editor
C++
5
star
21

mockups-creator

A NodeJS App that creates static HTML mockups using Grunt
JavaScript
5
star
22

jquery-itunestoresearch

A simple wrap to official iTunes Store Search API with jQuery
JavaScript
4
star
23

chrome-grooveshark-mediakeys-reloaded

Add multimedia keys support to Grooveshark
JavaScript
4
star
24

Moomba

Final Fantasy VIII CAM editor
C#
4
star
25

docker-gplayweb

GPlayWeb + FDroid Server + Caddy Server on one single Docker
Shell
4
star
26

typdom3

DOMPDF wrapper for TYPO3
PHP
4
star
27

tomahawk-daapjs

A DAAP resolver for Tomahawk made in Javascript
JavaScript
3
star
28

twypo

Twig for TYPO3
PHP
3
star
29

CaitSith

Final Fantasy VII CAM editor
C#
3
star
30

docker-pagekit

PHP Docker for Pagekit
2
star
31

JPM

A simple Json Package Manager
C#
2
star
32

jquery-youtubelivefeed

A simple jQuery plugin that will let you to embed live feeds or latest one made
JavaScript
2
star
33

ota.julianxhokaxhiu.com

Fully Automated Serverless OTA Service for LineageOS, using Github, Basketbuild, Cloudflare and Travis
JavaScript
2
star
34

PuPuSharp

FF8 Field Importer/Exporter - C# version of the original PuPu Project
C#
2
star
35

amazon-bot

JavaScript
2
star
36

FF78Launcher

An alternative launcher for FF7/FF8 Steam editions
CMake
2
star
37

bgfxCI

CI builds of bgfx for x86 platform
PowerShell
2
star
38

chrome-soundcloud-mediakeys-reloaded

Enable the use of MediaKeys for Soundcloud
JavaScript
2
star
39

polysticky.js

A position sticky polyfill that doesn't suck.
JavaScript
2
star
40

dotfiles

Collection of dotfiles improved overtime, based on Arch Linux
Shell
2
star
41

gulp-closurecompiler

The ClosureCompiler.js Gulp Task
JavaScript
2
star
42

FF7SND

Final Fantasy VII Audio Extraction app ( originally made by Qhimm.com )
C#
2
star
43

jquery-tagbox

A simple Facebook (or Google+) TagBox like using jQueryUI
JavaScript
1
star
44

MMNx

Next generation Mod Manager
CMake
1
star
45

ff8_mch

Final Fantasy VIII MCH Import/Export plugin for Blender
Python
1
star
46

docker-twrp-cicd

Docker microservice for TWRP Continuous Integration and Continous Deployment
Shell
1
star
47

DeliriNotturni-Live-Page

Live page of DeliriNotturni.org
JavaScript
1
star
48

rpi-powered-by-docker

Arch Linux ARM setup script to obtain a full RPI with Automatic Reverse Proxy (and more) without pain
Shell
1
star
49

ffmpegCI

CI builds of FFMpeg for x86 platform
PowerShell
1
star
50

chrome-youtube-mediakeys-reloaded

Enable the use of MediaKeys for Youtube
JavaScript
1
star
51

blog.julianxhokaxhiu.com

Julian Xhokaxhiu's Blog
HTML
1
star
52

vpngate-ovpn-exporter

Export all VPNGate OpenVPN configurations to files inside country-code relative folders
Python
1
star
53

AUR

My Arch Linux AUR Packages
Shell
1
star
54

LLGLCI

CI builds of LLGL for x86 platform
CMake
1
star
55

docker-iperf3

iPerf3 Server Container
Dockerfile
1
star
56

docker-nginx-reloaded

Reverse Proxy Docker container with Nginx, acme.sh, DNS and Autodiscovery ( alternative to jwilder/nginx-proxy )
Twig
1
star