gulp-prettier-plugin

raw JSON →
1.3.0 verified Sat Apr 25 auth: no javascript maintenance

Gulp plugin (v1.3.0, last release 2019) to format source code with Prettier. Requires Prettier >=1.x as a peer dependency. Key differentiator: supports filter mode (only emit files needing formatting) and validate mode (fail CI if files unformatted). Alternative to gulp-prettier with more granular control. Ships TypeScript definitions. Minimalist API with two optional config objects (prettier options and plugin options).

error TypeError: prettierPlugin is not a function
cause Using ES module import incorrectly (import * as).
fix
Use default import: import prettierPlugin from 'gulp-prettier-plugin' or const prettierPlugin = require('gulp-prettier-plugin').
error Error: Cannot find module 'prettier'
cause Prettier not installed; it's a peer dependency.
fix
Run: npm install prettier --save-dev
error gulp-dest: No files written
cause Forgetting to pass function to gulp.dest.
fix
Change .pipe(gulp.dest('./')) to .pipe(gulp.dest(file => file.base)).
deprecated Prettier v2+ has breaking changes; this plugin may not support all new options.
fix Consider using gulp-prettier (v4+) or use prettier directly.
gotcha pluginOptions.filter does not work correctly when piping to other gulp plugins after formatting, as it only emits changed files.
fix Set filter to false if you need to pipe output to other plugins (e.g., linter) for all files.
gotcha Must call gulp.dest with a function returning file.base to write in-place, otherwise files go to cwd.
fix Use `.pipe(gulp.dest(file => file.base))` instead of `.pipe(gulp.dest('./'))`.
gotcha Prettier options are not validated; invalid options are silently ignored.
fix Double-check Prettier option names and values.
npm install gulp-prettier-plugin
yarn add gulp-prettier-plugin
pnpm add gulp-prettier-plugin

Gulp task that formats JS files in place, using filter to only rewrite files that need formatting.

const gulp = require('gulp');
const prettierPlugin = require('gulp-prettier-plugin');

gulp.task('prettier', () =>
  gulp
    .src(['./src/**/*.js', './gulpfile.js'])
    .pipe(prettierPlugin({ singleQuote: true, trailingComma: 'all' }, { filter: true }))
    .pipe(gulp.dest(file => file.base))
);