gulp-usemin

2017-12-16  本文已影响118人  风之化身呀

1、作用及基本用法

一个html文件中一般会依赖多个css文件,该插件就是通过一种特殊的注释语法将所个css文件替换成一个。

var usemin = require('gulp-usemin');
gulp.task('usemin', function() {
  return gulp.src('./*.html')
    .pipe(usemin({options}))
    .pipe(gulp.dest('build/'));
});
//html特殊注释
<!-- build:css style.css -->
<link rel="stylesheet" href="css/clear.css"/>
<link rel="stylesheet" href="css/main.css"/>
<!-- endbuild -->
 
<!-- build:htmlimport components-packed.html -->
<link rel="import" href="components-a.html">
<link rel="import" href="components-b.html">
<!-- endbuild -->
 
<!-- build:js js/lib.js -->
<script src="../lib/angular-min.js"></script>
<script src="../lib/angular-animate-min.js"></script>
<!-- endbuild -->
 
<!-- build:js1 js/app.js -->
<script src="js/app.js"></script>
<script src="js/controllers/thing-controller.js"></script>
<script src="js/models/thing-model.js"></script>
<script src="js/views/thing-view.js"></script>
<!-- endbuild -->
 
<!-- build:remove -->
<script src="js/localhostDependencies.js"></script>
<!-- endbuild -->
 
<!-- build:inlinejs -->
<script src="../lib/angular-min.js"></script>
<script src="../lib/angular-animate-min.js"></script>
<!-- endbuild -->
 
<!-- build:inlinecss -->
<link rel="stylesheet" href="css/clear.css"/>
<link rel="stylesheet" href="css/main.css"/>
<!-- endbuild -->

2、注释语法

三个参数可以配置

... HTML Markup, list of script / link tags.

3、配置项

{
        async : true,
        defer:true,
        lorem : 'ipsum',
}

4、其他

gulp.task('usemin', function() {
  return gulp.src('./*.html')
    .pipe(usemin({
      css: [ rev ],
      html: [ function () {return htmlmin({ collapseWhitespace: true });} ],
      js: [ uglify, rev ],
      inlinejs: [ uglify ],
      inlinecss: [ cleanCss, 'concat' ]
    }))
    .pipe(gulp.dest('build/'));
});

gulp.task('usemin', ['sass'], function() { //
del('build/')
gulp.src([
_opt.src + 'view/ink-share.html'
], {
base: _opt.src
})
.pipe(gulpRevAll.revision({
prefix: 'http://1234.cloudfront.net/'
}))
.pipe(usemin({
css: [minifyCss(), gulpRevAll.revision({
hashLength: 4,
prefix: 'http://1234.cloudfront.net/'
})],
html: [function() {
return htmlmin({
collapseWhitespace: true
});
}],
js: [uglify(), gulpRevAll.revision({
hashLength: 4,
prefix: 'http://1234.cloudfront.net/'

        })],
        // inlinejs: [uglify],
        // inlinecss: [minifyCss, 'concat']
    }))
    .pipe(gulp.dest('build/'));

});

上一篇 下一篇

猜你喜欢

热点阅读