fmal / gulp-inline-source

Inline flagged js & css sources.
MIT License
212 stars 31 forks source link

gulp-inline-source

NPM Version Build Status Semantic Release Commitizen friendly

Inline all <script>, <link> and <img> tags that contain the inline attribute with inline-source.

How it works

<!-- located at src/html/index.html -->
<html>
  <head>
    <!-- inline src/js/inlineScript.js -->
    <script src="https://github.com/fmal/gulp-inline-source/raw/master/./js/inlineScript.js" inline></script>
  </head>
  <body>
  </body>
</html>
// located at src/js/inlineScript.js

function test() {
  var foo = 'lorem ipsum';
  return foo;
}

Output:

<html>
  <head>
    <script>function test(){var a="lorem ipsum";return a}</script>
  </head>
  <body>
  </body>
</html>

Install

$ npm install gulp-inline-source --save-dev

Usage

var gulp = require('gulp');
var inlinesource = require('gulp-inline-source');

gulp.task('inlinesource', function () {
    return gulp.src('./src/*.html')
        .pipe(inlinesource())
        .pipe(gulp.dest('./out'));
});

Optionally, you can provide some options through an options object:

var gulp = require('gulp');
var inlinesource = require('gulp-inline-source');

gulp.task('inlinesource', function () {
    var options = {
        compress: false
    };

    return gulp.src('./src/*.html')
        .pipe(inlinesource(options))
        .pipe(gulp.dest('./out'));
});