gulp and file structure overhaul
new gulp setup including new npm packages new file structure moved all development files to source/ used files are in build/ now
This commit is contained in:
parent
3a2140dad6
commit
a4a1fbc14d
56 changed files with 6912 additions and 5247 deletions
128
gulpfile.js
128
gulpfile.js
|
|
@ -1,43 +1,105 @@
|
|||
const gulp = require('gulp');
|
||||
const sass = require('gulp-ruby-sass');
|
||||
const sourcemaps = require('gulp-sourcemaps');
|
||||
const plumber = require('gulp-plumber');
|
||||
const notify = require('gulp-notify');
|
||||
const livereload = require('gulp-livereload');
|
||||
// Setup project
|
||||
var source = {
|
||||
styles: 'source/style/example.scss',
|
||||
scripts: ['source/code/variables.js', 'source/code/functions.js', 'source/code/global.js', 'source/code/**/*.coffee', '!source/vendor/**/*', ],
|
||||
images: 'source/art/**/*'
|
||||
};
|
||||
var build = {
|
||||
styles: 'build/css',
|
||||
scripts: 'build/js',
|
||||
images: 'build/art'
|
||||
}
|
||||
|
||||
gulp.task('default', function(){
|
||||
console.log('default gulp task...')
|
||||
// Load plugins
|
||||
const gulp = require('gulp'),
|
||||
rename = require('gulp-rename'),
|
||||
del = require('del');
|
||||
concat = require('gulp-concat'),
|
||||
pump = require('pump'),
|
||||
sourcemap = require('gulp-sourcemaps'),
|
||||
prefix = require('gulp-autoprefixer'),
|
||||
sass = require('gulp-ruby-sass'),
|
||||
cssnano = require('gulp-cssnano'),
|
||||
jshint = require('gulp-jshint'),
|
||||
uglify = require('gulp-uglify'),
|
||||
// imagemin = require('gulp-imagemin'),
|
||||
cache = require('gulp-cached'),
|
||||
remember = require('gulp-remember'),
|
||||
changed = require('gulp-changed'),
|
||||
notify = require('gulp-notify'),
|
||||
browsersync = require('browser-sync').create();
|
||||
|
||||
|
||||
// Task - Clean build directory
|
||||
gulp.task('clean', function() {
|
||||
return del([build.scripts, build.styles, 'build/**']);
|
||||
});
|
||||
|
||||
gulp.task('sass', () =>
|
||||
sass('./*.scss', {sourcemap: true})
|
||||
// .on('error', sass.logError)
|
||||
.pipe(plumber(errorReport("sass error")))
|
||||
.pipe(sourcemaps.write('./'))
|
||||
.pipe(gulp.dest('./'))
|
||||
.pipe(livereload())
|
||||
// Task - Styles
|
||||
gulp.task('styles', () =>
|
||||
sass(source.styles, {sourcemap: true})
|
||||
.on('error', sass.logError)
|
||||
.pipe(prefix('last 2 version'))
|
||||
.pipe(gulp.dest(build.styles))
|
||||
.pipe(rename({suffix: '.min'}))
|
||||
.pipe(cssnano())
|
||||
.pipe(sourcemap.write('.', {
|
||||
includeContent: false,
|
||||
sourceRoot: 'source'
|
||||
}))
|
||||
.pipe(gulp.dest(build.styles))
|
||||
.pipe(browsersync.stream({match: '**/*.css'}))
|
||||
// .pipe(notify({message: 'Style task complete'}))
|
||||
);
|
||||
|
||||
gulp.task('watch', function() {
|
||||
livereload.listen();
|
||||
gulp.watch('./**/*.scss', ['sass']);
|
||||
gulp.watch(['*.html']).on('change', livereload.changed);
|
||||
// gulp.watch('js/src/*.js', ['js']);
|
||||
// gulp.watch('img/src/*.{png,jpg,gif}', ['img']);
|
||||
|
||||
// Task - Scripts
|
||||
gulp.task('scripts', function(cb) {
|
||||
pump([
|
||||
gulp.src(source.scripts),
|
||||
cache('scripts'),
|
||||
jshint('.jshintrc'),
|
||||
jshint.reporter('default'),
|
||||
sourcemap.init(),
|
||||
uglify(),
|
||||
remember('scripts'),
|
||||
concat('all.min.js'),
|
||||
sourcemap.write(),
|
||||
gulp.dest(build.scripts),
|
||||
browsersync.stream()
|
||||
], cb);
|
||||
});
|
||||
|
||||
gulp.task('default', ['sass', 'watch']);
|
||||
// Task - Images
|
||||
gulp.task('images', function() {
|
||||
return gulp.src(source.images)
|
||||
.pipe(changed(cache(imagemin({
|
||||
optimizationLevel: 3,
|
||||
progressive: true,
|
||||
interlaced: true })))
|
||||
)
|
||||
.pipe(gulp.dest(build.images))
|
||||
.pipe(notify({ message: 'Images task complete' }))
|
||||
;
|
||||
});
|
||||
|
||||
// Watch for file changes
|
||||
gulp.task('watch', ['clean', 'styles', 'scripts'], function() {
|
||||
browsersync.init({
|
||||
server: ".",
|
||||
// proxy: "http://verser.vrt/virtual/"
|
||||
});
|
||||
|
||||
gulp.watch(source.styles, ['styles']);
|
||||
gulp.watch(source.scripts, ['scripts']).on('change', function(event) {
|
||||
if (event.type === 'deleted') {
|
||||
delete cache.caches['scripts'][event.path];
|
||||
remember.forget('scripts', event.path);
|
||||
}
|
||||
});
|
||||
gulp.watch("./*.html").on('change', browsersync.reload);
|
||||
// gulp.watch(['build/**']).on('change', browsersync.reload);
|
||||
// gulp.watch(source.images, ['images']);
|
||||
});
|
||||
|
||||
function errorReport(errTitle) {
|
||||
return plumber({
|
||||
errorHandler: notify.onError({
|
||||
// Customizing error title
|
||||
title: errTitle || "Error running Gulp",
|
||||
message: "Error: <%= error.message %>",
|
||||
sound: true
|
||||
})
|
||||
});
|
||||
}
|
||||
// The default task (called when you run `gulp` from cli)
|
||||
gulp.task('default', ['clean', 'styles', 'scripts']);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue