Giter Club home page Giter Club logo

gulp-inline's Introduction

gulp-inline

Information

Build Status codecov npm version

Packagegulp-inline
DescriptionInlines js/css/svg into your html files
Node Version= 0.10

Usage

var inline = require('gulp-inline')
  , uglify = require('gulp-uglify')
  , minifyCss = require('gulp-minify-css')
  , autoprefixer = require('gulp-autoprefixer');

gulp.src('public/index.html')
  .pipe(inline({
    base: 'public/',
    js: uglify,
    css: [minifyCss, autoprefixer({ browsers:['last 2 versions'] })],
    disabledTypes: ['svg', 'img', 'js'], // Only inline css files
    ignore: ['./css/do-not-inline-me.css']
  }))
  .pipe(gulp.dest('dist/'));

Replaces your <script> and <link> tags with the corresponding inlined files.

SVG support

Currently there are two supported methods:

  • <img> element with src attribute:

    <img src="/assets/icon.svg" class="MyClass" />
    

    which will be converted to something like

    <svg xmlns="http://www.w3.org/2000/svg" viewbox="..." class="MyClass">
      <circle ... />
      <path ... />
      etc.
    </svg>
    

    depending on what /assets/icon.svg contains

  • <svg> element with <use> child element:

    <svg>
      <use xlink:href="/assets/icon.svg#MyIdentifier"></use>
    </svg>
    

    Note that this method requires an ID matching the ID of target SVG root element.

    This is valid target SVG for the example above:

    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" id="MyIdentifier">
      ...
    </svg>
    

    while this is invalid:

    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
      ...
    </svg>
    

Options

Plugin options:

  • base - the root directory containing the files to be inlined
  • css - css transform (gulp plugin)
  • js - js transform (gulp plugin)
  • svg - svg transform (gulp plugin)
  • ignore - array of file paths to ignore and not inline (file paths as they appear in the source)
  • disabledTypes - array of types not to run inlining operations on (css, svg, js, img)

How to set options for uglify when used as plugin

Below is an example of how to pass options to uglify. In this case we tell uglify to not mangle function names.

var inline = require('gulp-inline')
  , uglify = require('gulp-uglify');

gulp.src('public/index.html')
  .pipe(inline({
    base: 'public/',
    js: function() {
      return uglify({
          mangle: false
      });
    }
  }))
  .pipe(gulp.dest('dist/'));

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.