Gathering detailed insights and metrics for gulp-usemin-stream
Gathering detailed insights and metrics for gulp-usemin-stream
Gathering detailed insights and metrics for gulp-usemin-stream
Gathering detailed insights and metrics for gulp-usemin-stream
npm install gulp-usemin-stream
Typescript
Module System
Min. Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Replaces references to non-optimized scripts or stylesheets into a set of HTML files (or any templates/views).
This task is designed for gulp 3.
Attention: v0.3.0 options is not compatible with v0.2.0.
First, install gulp-usemin
as a development dependency:
1npm install --save-dev gulp-usemin
Then, add it to your gulpfile.js
:
1var usemin = require('gulp-usemin'); 2var uglify = require('gulp-uglify'); 3var minifyHtml = require('gulp-minify-html'); 4var minifyCss = require('gulp-minify-css'); 5var rev = require('gulp-rev'); 6 7gulp.task('usemin', function() { 8 gulp.src('./*.html') 9 .pipe(usemin({ 10 css: [minifyCss(), 'concat'], 11 html: [minifyHtml({empty: true})], 12 js: [uglify(), rev()] 13 })) 14 .pipe(gulp.dest('build/')); 15});
Blocks are expressed as:
1<!-- build:<pipelineId>(alternate search path) <path> --> 2... HTML Markup, list of script / link tags. 3<!-- endbuild -->
An example of this in completed form can be seen below:
1<!-- build:css style.css --> 2<link rel="stylesheet" href="css/clear.css"/> 3<link rel="stylesheet" href="css/main.css"/> 4<!-- endbuild --> 5 6<!-- build:js js/lib.js --> 7<script src="../lib/angular-min.js"></script> 8<script src="../lib/angular-animate-min.js"></script> 9<!-- endbuild --> 10 11<!-- build:js1 js/app.js --> 12<script src="js/app.js"></script> 13<script src="js/controllers/thing-controller.js"></script> 14<script src="js/models/thing-model.js"></script> 15<script src="js/views/thing-view.js"></script> 16<!-- endbuild -->
Type: String
Alternate root path for assets. New concated js and css files will be written to the path specified in the build block, relative to this path. Currently asset files are also returned in the stream.
Type: Array
If exist used for modify files. If does not contain string 'concat', then it added as first member of pipeline
Type: String
Relative location to html file for new concatenated js and css.
|
+- app
| +- index.html
| +- assets
| +- js
| +- foo.js
| +- bar.js
| +- css
| +- clear.css
| +- main.css
+- dist
We want to optimize foo.js
and bar.js
into optimized.js
, referenced using relative path. index.html
should contain the following block:
<!-- build:css style.css -->
<link rel="stylesheet" href="css/clear.css"/>
<link rel="stylesheet" href="css/main.css"/>
<!-- endbuild -->
<!-- build:js js/optimized.js -->
<script src="assets/js/foo.js"></script>
<script src="assets/js/bar.js"></script>
<!-- endbuild -->
We want our files to be generated in the dist
directory. gulpfile.js
should contain the following block:
1gulp.task('usemin', function(){ 2 gulp.src('./app/index.html') 3 .pipe(usemin({ 4 js: [uglify()] 5 // in this case css will be only concatenated (like css: ['concat']). 6 })) 7 .pipe(gulp.dest('dist/')); 8});
This will generate the following output:
|
+- app
| +- index.html
| +- assets
| +- js
| +- foo.js
| +- bar.js
+- dist
| +- index.html
| +- js
| +- optimized.js
| +- style.css
index.html
output:
<link rel="stylesheet" href="style.css"/>
<script src="js/optimized.js"></script>
#####0.3.7
#####0.3.6
#####0.3.5
#####0.3.4
#####0.3.3
#####0.3.2
#####0.3.1
#####0.3.0
#####0.2.3
#####0.2.2
#####0.2.1
#####0.2.0
#####0.1.4
#####0.1.3
#####0.1.1
#####0.1.0
#####0.0.2
#####0.0.1
No vulnerabilities found.
No security vulnerabilities found.