-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05231b6
commit 5b9f53e
Showing
7 changed files
with
75 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: CI | ||
on: | ||
- push | ||
- pull_request | ||
jobs: | ||
test: | ||
name: Node.js ${{ matrix.node-version }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
node-version: | ||
- 20 | ||
- 18 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install | ||
- run: npm test |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,25 @@ | ||
'use strict'; | ||
const PluginError = require('plugin-error'); | ||
const through = require('through2'); | ||
const imageminWebp = require('imagemin-webp'); | ||
import imageminWebp from 'imagemin-webp'; | ||
import {gulpPlugin} from 'gulp-plugin-extras'; | ||
|
||
const supportedExtensions = new Set([ | ||
'png', | ||
'jpg', | ||
'jpeg', | ||
'tif', | ||
'tiff', | ||
'webp' | ||
'webp', | ||
]); | ||
|
||
module.exports = options => { | ||
export default function gulpWebp(options) { | ||
const instance = imageminWebp(options); | ||
|
||
return through.obj((file, encoding, callback) => { | ||
if (file.isNull()) { | ||
callback(null, file); | ||
return gulpPlugin('gulp-webp', async file => { | ||
if (!supportedExtensions.has(file.extname.slice(1).toLowerCase())) { | ||
return; | ||
} | ||
|
||
if (file.isStream()) { | ||
callback(new PluginError('gulp-webp', 'Streaming not supported')); | ||
return; | ||
} | ||
|
||
const ext = file.extname.slice(1).toLowerCase(); | ||
if (!supportedExtensions.has(ext)) { | ||
callback(null, file); | ||
return; | ||
} | ||
|
||
instance(file.contents) | ||
.then(result => { | ||
file.contents = result; | ||
file.extname = '.webp'; | ||
callback(null, file); | ||
}) | ||
.catch(error => { | ||
callback(new PluginError('gulp-webp', error, {fileName: file.path})); | ||
}); | ||
file.contents = await instance(file.contents); | ||
file.extname = '.webp'; | ||
return file; | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,32 @@ | ||
# gulp-webp [![Build Status](https://travis-ci.org/sindresorhus/gulp-webp.svg?branch=master)](https://travis-ci.org/sindresorhus/gulp-webp) | ||
# gulp-webp | ||
|
||
> Convert images to [WebP](https://developers.google.com/speed/webp/) | ||
Supports PNG, JPEG, TIFF, WebP. | ||
|
||
|
||
## Install | ||
|
||
``` | ||
$ npm install --save-dev gulp-webp | ||
```sh | ||
npm install --save-dev gulp-webp | ||
``` | ||
|
||
|
||
## Usage | ||
|
||
```js | ||
const gulp = require('gulp'); | ||
const webp = require('gulp-webp'); | ||
import gulp from 'gulp'; | ||
import webp from 'gulp-webp'; | ||
|
||
gulp.task('default', () => | ||
export default () => ( | ||
gulp.src('src/image.jpg') | ||
.pipe(webp()) | ||
.pipe(gulp.dest('dist')) | ||
); | ||
``` | ||
|
||
|
||
## API | ||
|
||
Note that unsupported files are ignored. | ||
|
||
### webp([options]) | ||
### webp(options?) | ||
|
||
See the `imagemin-webp` [options](https://github.com/imagemin/imagemin-webp#imageminwebpoptions). | ||
|
||
|
||
## License | ||
|
||
MIT © [Sindre Sorhus](https://sindresorhus.com) | ||
Unsupported files are ignored and passed through. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters