A better usemin.
npm install gulp-usemin-reloadedgulp-usemin-reloaded
====================
A better usemin.
build:something when you can write myrule:context?)``bash`
npm install gulp-usemin-reloaded
, 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.`javascript
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 and . 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
HTML
``html`
DICTIONARY
`javascript``
{
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 )
]
}
See LICENSE file.