Git Product home page Git Product logo

gulp-dom-src's 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.