# gulp-snippet-injector

> This is a gulp-injector to inject any snippet into a js file, you just need to specify the place you want to inject your snippet into.

Latest version **0.0.8** (published 2016-11-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install gulp-snippet-injector
pnpm add gulp-snippet-injector
yarn add gulp-snippet-injector
bun add gulp-snippet-injector
```

## 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.0.8 |
| Published | 2016-11-01 |
| First published | 2016-10-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Kat5ura |
| Maintainers | katsura |
| Keywords | gulpplugin |

## Links

- npm: https://www.npmjs.com/package/gulp-snippet-injector
- npm.io page: https://npm.io/package/gulp-snippet-injector

## Dependencies (4)

- [through2](https://npm.io/package/through2.md) ^2.0.1
- [gulp-util](https://npm.io/package/gulp-util.md) ^3.0.7
- [js-beautify](https://npm.io/package/js-beautify.md) ^1.6.4
- [inject-snippet](https://npm.io/package/inject-snippet.md) ^0.3.0

## Recent versions

- 0.0.8 (latest) — 2016-11-01
- 0.0.7 — 2016-10-25
- 0.0.6 — 2016-10-25
- 0.0.5 — 2016-10-25
- 0.0.4 — 2016-10-24
- 0.0.3 — 2016-10-24
- 0.0.2 — 2016-10-24
- 0.0.1 — 2016-10-24

## README

# gulp-replace

> A js snippet injector plugin for gulp

## Usage

First, install `gulp-snippet-injector` as a development dependency:

```shell
npm install --save-dev gulp-snippet-injector
```

Then, add it to your `gulpfile.js`:

### gulp task code
```javascript
var injector = require('gulp-snippet-injector');

gulp.task('injectSnippet', function(){
  gulp.src(['file.js'])
    .pipe(injector({
        code: 'console.log("Hello world");',
        entry: 'helloType'
    })
    .pipe(gulp.dest('build/file.js'));
});

gulp.task('injectAppend', function(){
  gulp.src(['file.js'])
    .pipe(injector({
        code: 'console.log("Hello world");',
        entry: 'appendEntry',
        mode: 'append'
    })
    .pipe(gulp.dest('build/file.js'));
});

```
### file.js
```javascript
// ..... some code

/* inject:helloEntry start */

// your snippet will be injected into this field 

/* inject:helloEntry end */

/* inject:appendEntry start */

/* inject:appendEntry end */

// your snippet will be injected into this field 

// ..... some code
```


## API

gulp-snippet-injector need one argument, which is an ***Object*** telling the gulp the snippet you want to inject and the type of your snippet.

### injector([options])

#### options
Type: `Object or [Object]`

##### options.code

Type: `String`  

Default: `''`

Description: `The code snippet you want to inject into the target js file.`

#### options.entry

Type: `String`

Default: `''`

Description: `A string you can use to distinguish the entry where your snippet inject into. `

#### options.mode

Type: `String` | `inside / append / prepend`

Default: `''`

Description: `A string you can use to specify a mode, code can be appended or prepended to the entry, default is inside the entry`

### inject(filePath, [options], disPath)

You can use a exported function named ***inject*** via:

```javascript

var inject = require('gulp-snippet-inject').inject

inject('path/to/file.js', {
    code: 'console.log("Hello world!")',
    entry: 'helloEntry'
})

```

## License

MIT

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