• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

cgross/gulp-dom-src: Create a gulp stream from script, link, or any set of tags ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

cgross/gulp-dom-src

开源软件地址(OpenSource Url):

https://github.com/cgross/gulp-dom-src

开源编程语言(OpenSource Language):

JavaScript 89.6%

开源软件介绍(OpenSource Introduction):

gulp-dom-src Build Status

Create a gulp stream from script, link, or any set of tags in an HTML file.

Example

var gulp = require('gulp');
var domSrc = require('gulp-dom-src');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');

gulp.task('default', function () {
	domSrc({ file: 'index.html', selector: 'script', attribute: 'src' })
        .pipe(concat('app.full.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('dist/'));
});

API

domSrc(config)

config.file

Type: String

The name of the HTML file to read the tags from.

config.selector

Type: String

Any valid CSS selector. You can use complex selectors to allow flexible include/exclude logic for your tags. For example, use a selector such as script[data-concat!="false"] and put data-concat="false" on any script tags you wish to exclude from a concat/minification stream.

config.attribute

Type: String

The name of the attribute that contains the file path. Typically src for script tags and href for links.

config.cwd

Type: String (Optional)

The directory where the paths in your tags are relative to. By default, the files references in your script or link tags are assumed to be relative to the HTML file they're read from.

config.options

Type: Object (Optional) Default: {}

Options passed through to the underlying vinyl-fs. Can include options like read and buffer.

domSrc.duplex(config)

Creates a stream that html files can be piped into -- html files in, script or style files out.

config.selector, config.attribute, config.cwd

See above

End-to-End Concatenation and Minification

Combine gulp-dom-src with gulp-cheerio for a full concat & min workflow.

var gulp = require('gulp');
var domSrc = require('gulp-dom-src');
var concat = require('gulp-concat');
var cssmin = require('gulp-cssmin');
var uglify = require('gulp-uglify');
var cheerio = require('gulp-cheerio');

gulp.task('css', function() {
    return domSrc({file:'index.html',selector:'link',attribute:'href'})
    	.pipe(concat('app.full.min.css'))
        .pipe(cssmin())
        .pipe(gulp.dest('dist/'));
});

gulp.task('js', function() {
    return domSrc({file:'index.html',selector:'script',attribute:'src'})
        .pipe(concat('app.full.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('dist/'));
});

gulp.task('indexHtml', function() {
    return gulp.src('index.html')
        .pipe(cheerio(function ($) {
            $('script').remove();
            $('link').remove();
            $('body').append('<script src="app.full.min.js"></script>');
            $('head').append('<link rel="stylesheet" href="app.full.min.css">');
        }))
        .pipe(gulp.dest('dist/'));
});

Release History

  • 4/12/2015 - v0.2.0 - Added duplex feature from @psalaets.
  • 3/17/2014 - v0.1.1 - Added cwd option.
  • 3/08/2014 - v0.1.0 - Initial release.



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap