# gulp-file-inject

> A Gulp task to do a regex replace with dynamic content based on the source file

Latest version **0.1.2** (published 2015-04-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install gulp-file-inject
pnpm add gulp-file-inject
yarn add gulp-file-inject
bun add gulp-file-inject
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2015-04-03 |
| First published | 2015-04-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kiril Vatev |
| Maintainers | kirilv |

## Links

- npm: https://www.npmjs.com/package/gulp-file-inject
- Repository: https://github.com/catdad/gulp-file-inject
- Issues: https://github.com/catdad/gulp-file-inject/issues
- npm.io page: https://npm.io/package/gulp-file-inject

## Dependencies (2)

- [through2](https://npm.io/package/through2.md) ^0.6.3
- [replacestream](https://npm.io/package/replacestream.md) ^2.1.0

## Recent versions

- 0.1.2 (latest) — 2015-04-03
- 0.1.1 — 2015-04-01
- 0.1.0 — 2015-04-01
- 0.0.2 — 2015-04-01
- 0.0.1 — 2015-04-01

## README

# gulp-file-inject

### Install:

    npm install -D gulp-file-inject
    
### Use:

    var gulp = require('gulp');
    var inject = require('gulp-file-inject');
    
    var fs = require('fs');
    
    function replacer(filepath, filename, callback) {
        // template to inject
        var str = "var template = '{{template}}'";
        
        // get the html file by the same name
        fs.readFile(filename.replace('.js', '.html'), function(err, file) {
            if (err) {
                return callback(err);
            }
            
            // make sure you minify the html first
            file = file.replace(/\n\r/, ' ').replace("'", '"');
            str = str.replace('{{template}}', file);
            callback(undefined, str);
        });
    }
    
    gulp.task('inject', function(){
        return gulp.src('js/*.js')
            .pipe(inject(/myregex/g, replacer))
            .pipe(gulp.dest('build/js'));
    });
    
### Notes:

More docs are soon to come, I promise.

This is heavily based on [gulp-replace](https://github.com/lazd/gulp-replace) by [lazd](https://github.com/lazd).

[![Analytics](https://ga-beacon.appspot.com/UA-17159207-7/gulp-file-inject/readme)](https://github.com/igrigorik/ga-beacon)

---
_Source: https://npm.io/package/gulp-file-inject · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
