gulp (scss) fix

This commit is contained in:
Jan Jastrow 2020-05-28 11:23:33 +02:00
parent 7d56533ed0
commit 329c563a41
4 changed files with 63 additions and 34 deletions

View File

@ -1,5 +1,11 @@
# Changelog # Changelog
## 3.0.3 (2020-05-28)
- Fixed gulp script (cssnano)
- Seperated scss tasks
- minor structure update
## 3.0.2 (2020-05-04) ## 3.0.2 (2020-05-04)
- Updated npm dependencies - Updated npm dependencies

View File

@ -1,7 +1,8 @@
'use strict' 'use strict';
//---------------- //------------------------
//:: Initiate npm-modules //:: Initiate npm-modules
const gulp = require('gulp'), const gulp = require('gulp'),
sass = require('gulp-sass'), sass = require('gulp-sass'),
concat = require('gulp-concat'), concat = require('gulp-concat'),
@ -15,8 +16,10 @@ const gulp = require('gulp'),
merge2 = require('merge2'), merge2 = require('merge2'),
rimraf = require('rimraf'); rimraf = require('rimraf');
//----------------
//:: configs //------------------------
//:: Config parameter
var Config = { var Config = {
inputDir: '_source/', inputDir: '_source/',
outputDir: '_dist/' outputDir: '_dist/'
@ -30,22 +33,18 @@ var SassConfig = {
} }
} }
var postcss_plugins = [
cssnano,
autoprefixer
];
//---------------- //------------------------
//:: Tasks //:: Tasks
// compile scss // compile scss
function scss() { function scss_addons() {
var onError = function(err) { var onError = function(err) {
notify.onError({ notify.onError({
title: 'gulp', title: 'scss_addons',
subtitle: 'Error!', subtitle: 'Error!',
message: '❌ <%= error.message %>', message: '❌ <%= error.message %>',
sound: 'Submarine' sound: 'Submarine'
})(err); })(err);
this.emit('end'); this.emit('end');
}; };
@ -55,22 +54,44 @@ function scss() {
'node_modules/sanitize.css/sanitize.css' 'node_modules/sanitize.css/sanitize.css'
])) ]))
.pipe(concat('addons.css')) .pipe(concat('addons.css'))
.pipe(postcss([autoprefixer()]))
.pipe(gulp.dest(SassConfig.outputDir)) .pipe(gulp.dest(SassConfig.outputDir))
.pipe(postcss(postcss_plugins)) .pipe(postcss([cssnano()]))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(SassConfig.outputDir)),
gulp.src(SassConfig.inputDir + '*.scss')
.pipe(concat('styles.css'))
.pipe(plumber({errorHandler: onError}))
.pipe(postcss(postcss_plugins))
.pipe(sass(SassConfig.options).on('error', sass.logError))
.pipe(gulp.dest(SassConfig.outputDir))
.pipe(rename({suffix: '.min'})) .pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(SassConfig.outputDir)) .pipe(gulp.dest(SassConfig.outputDir))
.pipe(livereload()) .pipe(livereload())
.pipe(notify({ .pipe(notify({
title: 'gulp', title: 'scss_addons',
subtitle: 'Success!',
message: '✅ SCSS compiled',
timeout: '2'
}));
}
function scss_main() {
var onError = function(err) {
notify.onError({
title: 'scss_main',
subtitle: 'Error!',
message: '❌ <%= error.message %>',
sound: 'Submarine'
})(err);
this.emit('end');
};
return gulp
.src(SassConfig.inputDir + '*.scss')
.pipe(concat('styles.css'))
.pipe(plumber({errorHandler: onError}))
.pipe(sass(SassConfig.options).on('error', sass.logError))
.pipe(postcss([autoprefixer()]))
.pipe(gulp.dest(SassConfig.outputDir))
.pipe(postcss([cssnano()]))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(SassConfig.outputDir))
.pipe(livereload())
.pipe(notify({
title: 'scss_main',
subtitle: 'Success!', subtitle: 'Success!',
message: '✅ SCSS compiled', message: '✅ SCSS compiled',
timeout: '2' timeout: '2'
@ -79,16 +100,16 @@ function scss() {
// Copy those other files // Copy those other files
function copy(done) { function copy(done) {
gulp.src([Config.inputDir + '*.*']) gulp.src([Config.inputDir + '**/*.*'])
.pipe(gulp.dest(Config.outputDir)) .pipe(gulp.dest(Config.outputDir))
.pipe(livereload()) .pipe(livereload())
done(); done();
}; };
// watch for changes // Watch for changes
function watch() { function watch() {
livereload.listen(); livereload.listen();
gulp.watch(SassConfig.inputDir + '*.scss', scss); gulp.watch(SassConfig.inputDir + '*.scss', scss_main);
gulp.watch(Config.inputDir + '*.html', copy); gulp.watch(Config.inputDir + '*.html', copy);
}; };
@ -97,14 +118,16 @@ function cleanup(cb) {
return rimraf(Config.outputDir + '*', cb) return rimraf(Config.outputDir + '*', cb)
}; };
//----------------
//:: Export tasks //------------------------
//:: Define tasks
// complex tasks // complex tasks
const build = gulp.series(cleanup, gulp.parallel(copy, scss)); const build = gulp.series(cleanup, gulp.parallel(copy, scss_addons, scss_main));
// export tasks // export tasks
exports.scss = scss; exports.scss_main = scss_main;
exports.scss_addons = scss_addons;
exports.copy = copy; exports.copy = copy;
exports.watch = watch; exports.watch = watch;
exports.cleanup = cleanup; exports.cleanup = cleanup;

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "website_template", "name": "website_template",
"version": "3.0.2", "version": "3.0.3",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,7 +1,7 @@
{ {
"name": "website_template", "name": "website_template",
"description": "npm & gulp development template", "description": "npm & gulp development template",
"version": "3.0.2", "version": "3.0.3",
"author": "Jan Jastrow", "author": "Jan Jastrow",
"license": "MIT", "license": "MIT",
"homepage": "https://jan.jastrow.me", "homepage": "https://jan.jastrow.me",