Skip to content

Instantly share code, notes, and snippets.

@nilsbosman
Last active November 8, 2021 10:19
Show Gist options
  • Save nilsbosman/6d817892104ac8b4b03c9139e9ed1e07 to your computer and use it in GitHub Desktop.
Save nilsbosman/6d817892104ac8b4b03c9139e9ed1e07 to your computer and use it in GitHub Desktop.
Gulp4 - Tailwind and SCSS
// Load plugins
const gulp = require("gulp");
const sass = require('gulp-sass')(require('sass'));
const postcss = require("gulp-postcss");
const cssnano = require("gulp-cssnano");
const concat = require("gulp-concat");
const autoprefixer = require("autoprefixer");
// CSS task
function styles() {
var tailwindcss = require('tailwindcss');
return gulp
// start with getting the tailwind.css file
.src("./src/css/tailwind.css")
// use postcss to compile it.
.pipe(postcss([
tailwindcss('./tailwind.config.js')
]))
// Add new source with your .scss
.pipe(gulp.src("./src/css/**/*.scss"))
// Compile to css
.pipe(sass())
// Concat both files into one styles.css file
.pipe(concat("style.css"))
// Run postcss again with just autoprefixer so it runs on both files
.pipe(postcss([
require('autoprefixer'),
]))
// Minimise the css file
.pipe(cssnano())
// write css file to the filesystem
.pipe(gulp.dest("./"))
}
// define tasks
const css = gulp.series(styles);
// export tasks
exports.css = css;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment