Gathering detailed insights and metrics for gulp-postcss
Gathering detailed insights and metrics for gulp-postcss
Gathering detailed insights and metrics for gulp-postcss
Gathering detailed insights and metrics for gulp-postcss
Pipe CSS through PostCSS processors with a single parse
npm install gulp-postcss
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
769 Stars
179 Commits
65 Forks
19 Watching
1 Branches
32 Contributors
Updated on 15 Jul 2024
JavaScript (97.85%)
Nix (2.15%)
Cumulative downloads
Total Downloads
Last day
2.1%
37,900
Compared to previous day
Last week
2.7%
205,129
Compared to previous week
Last month
0.5%
863,091
Compared to previous month
Last year
15.5%
10,423,340
Compared to previous year
1
8
PostCSS gulp plugin to pipe CSS through several plugins, but parse CSS only once.
$ npm install --save-dev postcss gulp-postcss
Install required postcss plugins separately. E.g. for autoprefixer, you need to install autoprefixer package.
The configuration is loaded automatically from postcss.config.js
as described here,
so you don't have to specify any options.
1var postcss = require('gulp-postcss'); 2var gulp = require('gulp'); 3 4gulp.task('css', function () { 5 return gulp.src('./src/*.css') 6 .pipe(postcss()) 7 .pipe(gulp.dest('./dest')); 8});
1var postcss = require('gulp-postcss'); 2var gulp = require('gulp'); 3var autoprefixer = require('autoprefixer'); 4var cssnano = require('cssnano'); 5 6gulp.task('css', function () { 7 var plugins = [ 8 autoprefixer({browsers: ['last 1 version']}), 9 cssnano() 10 ]; 11 return gulp.src('./src/*.css') 12 .pipe(postcss(plugins)) 13 .pipe(gulp.dest('./dest')); 14});
For using gulp-postcss to have input files in .pcss format and get .css output need additional library like gulp-rename.
1var postcss = require('gulp-postcss'); 2var gulp = require('gulp'); 3const rename = require('gulp-rename'); 4 5gulp.task('css', function () { 6 return gulp.src('./src/*.pcss') 7 .pipe(postcss()) 8 .pipe(rename({ 9 extname: '.css' 10 })) 11 .pipe(gulp.dest('./dest')); 12});
This is done for more explicit transformation. According to gulp plugin guidelines
Your plugin should only do one thing, and do it well.
The second optional argument to gulp-postcss is passed to PostCSS.
This, for instance, may be used to enable custom parser:
1var gulp = require('gulp'); 2var postcss = require('gulp-postcss'); 3var nested = require('postcss-nested'); 4var sugarss = require('sugarss'); 5 6gulp.task('default', function () { 7 var plugins = [nested]; 8 return gulp.src('in.sss') 9 .pipe(postcss(plugins, { parser: sugarss })) 10 .pipe(gulp.dest('out')); 11});
If you are using a postcss.config.js
file, you can pass PostCSS options as the first argument to gulp-postcss.
This, for instance, will let PostCSS know what the final file destination path is, since it will be unaware of the path given to gulp.dest()
:
1var gulp = require('gulp'); 2var postcss = require('gulp-postcss'); 3 4gulp.task('default', function () { 5 return gulp.src('in.scss') 6 .pipe(postcss({ to: 'out/in.css' })) 7 .pipe(gulp.dest('out')); 8});
1var postcss = require('gulp-postcss'); 2var cssnext = require('postcss-cssnext'); 3var opacity = function (css, opts) { 4 css.walkDecls(function(decl) { 5 if (decl.prop === 'opacity') { 6 decl.parent.insertAfter(decl, { 7 prop: '-ms-filter', 8 value: '"progid:DXImageTransform.Microsoft.Alpha(Opacity=' + (parseFloat(decl.value) * 100) + ')"' 9 }); 10 } 11 }); 12}; 13 14gulp.task('css', function () { 15 var plugins = [ 16 cssnext({browsers: ['last 1 version']}), 17 opacity 18 ]; 19 return gulp.src('./src/*.css') 20 .pipe(postcss(plugins)) 21 .pipe(gulp.dest('./dest')); 22});
Source map is disabled by default, to extract map use together with gulp-sourcemaps.
1return gulp.src('./src/*.css') 2 .pipe(sourcemaps.init()) 3 .pipe(postcss(plugins)) 4 .pipe(sourcemaps.write('.')) 5 .pipe(gulp.dest('./dest'));
If you want to configure postcss on per-file-basis, you can pass a callback
that receives vinyl file object and returns
{ plugins: plugins, options: options }
. For example, when you need to
parse different extensions differntly:
1var gulp = require('gulp'); 2var postcss = require('gulp-postcss'); 3 4gulp.task('css', function () { 5 function callback(file) { 6 return { 7 plugins: [ 8 require('postcss-import')({ root: file.dirname }), 9 require('postcss-modules') 10 ], 11 options: { 12 parser: file.extname === '.sss' ? require('sugarss') : false 13 } 14 } 15 } 16 return gulp.src('./src/*.css') 17 .pipe(postcss(callback)) 18 .pipe(gulp.dest('./dest')); 19});
The same result may be achieved with
postcss-load-config
,
because it receives ctx
with the context options and the vinyl file.
1var gulp = require('gulp'); 2var postcss = require('gulp-postcss'); 3 4gulp.task('css', function () { 5 var contextOptions = { modules: true }; 6 return gulp.src('./src/*.css') 7 .pipe(postcss(contextOptions)) 8 .pipe(gulp.dest('./dest')); 9});
1// postcss.config.js or .postcssrc.js 2module.exports = function (ctx) { 3 var file = ctx.file; 4 var options = ctx; 5 return { 6 parser: file.extname === '.sss' ? : 'sugarss' : false, 7 plugins: { 8 'postcss-import': { root: file.dirname } 9 'postcss-modules': options.modules ? {} : false 10 } 11 } 12};
10.0.0
9.1.0 deprecated, because it breaks semver by dropping support for node <18
nix develop
9.0.1
9.0.0
8.0.0
7.0.1
7.0.0
6.4.0
PluginError
object6.3.0
6.2.0
6.1.1
6.1.0
null
files6.0.1
syntax
option)6.0.0
5.1.10
5.1.9
5.1.8
5.1.7
5.1.6
CssSyntaxError
check5.1.4
5.1.3 Updated travis banner
5.1.2 Transferred repo into postcss org on github
5.1.1
to
option5.1.0 PostCSS Runner Guidelines
from
and to
processing optionsCssSyntaxError
result.warnings()
content5.0.1
5.0.0
4.0.3
4.0.2
4.0.1
4.0.0
3.0.0
2.0.1
2.0.0
1.0.2
1.0.1
1.0.0
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 5/11 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More