mirror of
https://github.com/ViViDboarder/Vivid-Casper.git
synced 2024-11-14 01:06:32 +00:00
bef56a2294
no issue - Added a `js` task to run on the gulp build process and minifies our js files - Changed the required scripts in `default.hbs` to use the minified js files in `/built/` - Moved existing `js` tasks from `zip` task
88 lines
2.2 KiB
JavaScript
88 lines
2.2 KiB
JavaScript
var gulp = require('gulp');
|
|
|
|
// gulp plugins and utils
|
|
var gutil = require('gulp-util');
|
|
var livereload = require('gulp-livereload');
|
|
var postcss = require('gulp-postcss');
|
|
var sourcemaps = require('gulp-sourcemaps');
|
|
var zip = require('gulp-zip');
|
|
var uglify = require('gulp-uglify');
|
|
var filter = require('gulp-filter');
|
|
|
|
// postcss plugins
|
|
var autoprefixer = require('autoprefixer');
|
|
var colorFunction = require('postcss-color-function');
|
|
var cssnano = require('cssnano');
|
|
var customProperties = require('postcss-custom-properties');
|
|
var easyimport = require('postcss-easy-import');
|
|
|
|
var swallowError = function swallowError(error) {
|
|
gutil.log(error.toString());
|
|
gutil.beep();
|
|
this.emit('end');
|
|
};
|
|
|
|
var nodemonServerInit = function () {
|
|
livereload.listen(1234);
|
|
};
|
|
|
|
gulp.task('build', ['css', 'js'], function (/* cb */) {
|
|
return nodemonServerInit();
|
|
});
|
|
|
|
gulp.task('generate', ['css', 'js']);
|
|
|
|
gulp.task('css', function () {
|
|
var processors = [
|
|
easyimport,
|
|
customProperties,
|
|
colorFunction(),
|
|
autoprefixer({browsers: ['last 2 versions']}),
|
|
cssnano()
|
|
];
|
|
|
|
return gulp.src('assets/css/*.css')
|
|
.on('error', swallowError)
|
|
.pipe(sourcemaps.init())
|
|
.pipe(postcss(processors))
|
|
.pipe(sourcemaps.write('.'))
|
|
.pipe(gulp.dest('assets/built/'))
|
|
.pipe(livereload());
|
|
});
|
|
|
|
gulp.task('js', function () {
|
|
var jsFilter = filter(['**/*.js'], {restore: true});
|
|
|
|
return gulp.src('assets/js/*.js')
|
|
.on('error', swallowError)
|
|
.pipe(sourcemaps.init())
|
|
.pipe(jsFilter)
|
|
.pipe(uglify())
|
|
.pipe(jsFilter.restore)
|
|
.pipe(sourcemaps.write('.'))
|
|
.pipe(gulp.dest('assets/built/'))
|
|
.pipe(livereload());
|
|
});
|
|
|
|
gulp.task('watch', function () {
|
|
gulp.watch('assets/css/**', ['css']);
|
|
});
|
|
|
|
gulp.task('zip', ['css', 'js'], function () {
|
|
var targetDir = 'dist/';
|
|
var themeName = require('./package.json').name;
|
|
var filename = themeName + '.zip';
|
|
|
|
return gulp.src([
|
|
'**',
|
|
'!node_modules', '!node_modules/**',
|
|
'!dist', '!dist/**'
|
|
])
|
|
.pipe(zip(filename))
|
|
.pipe(gulp.dest(targetDir));
|
|
});
|
|
|
|
gulp.task('default', ['build'], function () {
|
|
gulp.start('watch');
|
|
});
|