Coder Social home page Coder Social logo

gulp-inject's Introduction

gulp-inject NPM version Build Status Dependency Status

A stylesheet, javascript and webcomponent reference injection plugin for gulp. No more manual editing of your index.html!

Usage

First, install gulp-inject as a development dependency:

npm install --save-dev gulp-inject

Then, add it to your gulpfile.js:

var inject = require("gulp-inject");

gulp.src("./src/*.ext", {read: false}) // Not necessary to read the files (will speed up things), we're only after their paths
	.pipe(inject("path/to/your/index.html"))
	.pipe(gulp.dest("./dist"));

Add injection tags to your index.html:

<!DOCTYPE html>
<html>
<head>
  <title>My index</title>
  <!-- inject:html -->
  <!-- any *.html files among your sources will go here as: <link rel="import" href="FILE"> -->
  <!-- endinject -->
  <!-- inject:css -->
  <!-- any *.css files among your sources will go here as: <link rel="stylesheet" href="FILE"> -->
  <!-- endinject -->
</head>
<body>

  <!-- inject:js -->
  <!-- any *.js files among your sources will go here as: <script src="FILE"></script> -->
  <!-- endinject -->
</body>
</html>

API

inject(filename, options)

filename

Type: String

Path to template file (where your injection tags are). Is also used as filename for the plugin's output file.

options.templateString

Type: String

Default: NULL

Is used as template instead of the contents of given filename.

options.ignorePath

Type: String or Array

Default: NULL

A path or paths that should be removed from each injected file path.

options.addRootSlash

Type: Boolean

Default: true

The root slash is automatically added at the beginning of the path ('/').

options.starttag

Type: String

Default: <!-- inject:{{ext}} -->

Set the start tag that the injector is looking for. {{ext}} is replaced with file extension name, e.g. "css", "js" or "html".

options.endtag

Type: String

Default: <!-- endinject -->

Set the end tag that the injector is looking for. {{ext}} is replaced with file extension name, e.g. "css", "js" or "html".

options.transform

Type: Function(filepath, file, index, length)

Params:

  • filepath - The "unixified" path to the file with any ignorePath's removed
  • file - The File object given from gulp.src
  • index (0-based file index)
  • length (total number of files to inject)

Default: a function that returns:

  • For css files: <link rel="stylesheet" href="<filename>.css">
  • For js files: <script src="<filename>.js"></script>
  • For html files: <link rel="import" href="<filename>.html">

Used to generate the content to inject for each file.

options.sort

Type: Function(a, b)

Params: a, b (is used as compareFunction for Array.prototype.sort)

Default: NULL

If set the given function is used as the compareFunction for the array sort function, to sort the source files by.

License

MIT License

gulp-inject's People

Contributors

joakimbeng avatar koblass avatar overzealous avatar

Watchers

Navid Nikpour avatar  avatar

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.