1
0
mirror of https://github.com/stisla/stisla.git synced 2025-08-30 11:30:07 +02:00

Merge pull request #7 from iqbalaqaba/master

Gulp
This commit is contained in:
Muhamad Nauval Azhar
2019-02-11 10:44:13 +07:00
committed by GitHub
2 changed files with 189 additions and 52 deletions

125
gulpfile.js Normal file
View File

@@ -0,0 +1,125 @@
// Gulp file config by iqbal
const {src, dest, watch, parallel} = require('gulp');
const notify = require('gulp-notify');
const browserSync = require('browser-sync').create();
const sass = require('gulp-sass');
const concat = require('gulp-concat');
const plumber = require('gulp-plumber');
const rename = require('gulp-rename');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const uglify = require('gulp-uglify');
const imagemin = require('gulp-imagemin');
const imageminMozjpeg = require('imagemin-mozjpeg');
//dir
var cssDir = './assets/css';
var jsDir = './assets/js';
var sassDir = './assets/sass/*.scss';
var imgDir = './assets/img/*';
//css
var cssFileOne = 'path';
var cssFileTwo = 'path';
var cssFileThree = 'path';
//js
var jsFileOne = 'path';
var jsFileTwo = 'path';
var jsFileThree = 'path';
// moving js
function js(){
return src([jsFileOne, jsFileTwo, jsFileThree])
.pipe(plumber())
.pipe(concat('plugin.min.js'))
.pipe(uglify())
.pipe(dest(jsDir))
.pipe(notify({
message: 'File <%= file.relative %> wis dadi'
}));
}
// moving css
function css(){
return src([cssFileOne,cssFileTwo,cssFileThree,])
.pipe(plumber())
.pipe(concat('plugin.min.css'))
.pipe(postcss([autoprefixer(), cssnano()]))
.pipe(dest(cssDir))
.pipe(notify({
message: 'File <%= file.relative %> wis dadi'
}));
}
//make structural folder
function folder(){
return src('*.*', {read: false})
.pipe(dest('./sandbox/_test'))
.pipe(dest('./assets'))
.pipe(dest('./assets/sass'))
.pipe(dest('./assets/css'))
.pipe(dest('./assets/js'))
.pipe(dest('./assets/img'))
}
//minify compile
function minify(){
return src(sassDir)
.pipe(plumber())
.pipe(sass({
errorLogToConsole: true
}))
.on('error', console.error.bind( console ))
.pipe(rename({
suffix: '.min'
}))
.pipe(postcss([autoprefixer(), cssnano()]))
.pipe(dest(cssDir))
.pipe(notify({
message: 'Minify <%= file.relative %> berhasil bos'
}));
}
//minfy image
function image(){
return src(imgDir)
.pipe(plumber())
.pipe(imagemin([
imageminMozjpeg({quality: 80})
]))
.pipe(dest(imgDir))
.pipe(plumber.stop())
}
function watching (){
browserSync.init({
server:{
baseDir: "./"
},
port: 8080
});
watch('./assets/sass/*.scss',minify).on('change',browserSync.reload);
watch("*.html").on('change',browserSync.reload);
}
function watchcss(){
watch('./assets/sass/*.scss',minify);
}
//create folder first
exports.folder = folder;
//then update source
exports.update = parallel(js, css);
//updating JS SOURCE ONLY
exports.js = js;
//updating CSS SOURCE ONLY
exports.css = css;
//minify IMG SOURCE
exports.image = image;
//Run this command for styling OPs
exports.minify = minify;
//Run this command for dev.
exports.default = watching;

View File

@@ -47,6 +47,18 @@
"jquery-sparkline": "https://github.com/gwatts/jquery.sparkline" "jquery-sparkline": "https://github.com/gwatts/jquery.sparkline"
}, },
"devDependencies": { "devDependencies": {
"gulp": "^4.0.0" "gulp": "^4.0.0",
"autoprefixer": "^9.4.7",
"browser-sync": "^2.26.3",
"cssnano": "^4.1.8",
"gulp-concat": "^2.6.1",
"gulp-imagemin": "^5.0.3",
"gulp-notify": "^3.2.0",
"gulp-plumber": "^1.2.1",
"gulp-postcss": "^8.0.0",
"gulp-rename": "^1.4.0",
"gulp-sass": "^4.0.2",
"gulp-uglify": "^3.0.1",
"imagemin-mozjpeg": "^8.0.0"
} }
} }