Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/philmander/gulp-warn-size

Gulp plugin that warns when a file exceeds a given size limit"
https://github.com/philmander/gulp-warn-size

Last synced: about 1 month ago
JSON representation

Gulp plugin that warns when a file exceeds a given size limit"

Awesome Lists containing this project

README

        

# gulp-warn-size

> Warns if a file in a stream exceeds a given limit

## Install

```
$ npm install --save-dev gulp-warn-size
```

## Usage

```js
const gulp = require('gulp');
const size = require('gulp-warn-size');

gulp.task('default', () =>
gulp.src('fixture.js')
.pipe(warn-size(2048)) //should not exceed 2kb
.on('error', () => process.exit(1))
.pipe(gulp.dest('dist'))
);
```

`gulp-warn-size` does not display sizes. Use [gulp-size](https://github.com/sindresorhus/gulp-size) for this.

## API

### warn-size(limit)

Type: `number`

Required

The file size limit in bytes. Negative values will be ignored. Other values will cause the plugin to fail.

### warn-size(options)

#### options

##### limit

Type: `number`

Required

Same as above

##### errorOnFail

Type: `boolean`

Default: `true`

Emits an error from the stream if a file exceeds the given limit. Otherwise, just a warning will be logged to the console

##### filter

Type: `RegExp`

Default: /.*/

Only applies file size checking to files which match this pattern. E.g.

```
gulp.src('src/**/*')
.pipe(warn-size({
limit: 2048,
filter: /\.js$/ //only check JS files
}))
.pipe(gulp.dest('dist'))
```

##### pretty

Type: `boolean`

Default: true

Displays prettified size: `1337 B` → `1.34 kB`.

## License

MIT. Phil Mander.

Adapted from gulp-size