Created
October 24, 2017 23:25
-
-
Save javiercastrodev/c4d5d7deb18bea4aa4fb58af5ac4004f to your computer and use it in GitHub Desktop.
gulp php + vuejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var gulp = require('gulp'), | |
cache = require('gulp-cache'), | |
browserSync = require('browser-sync').create(), | |
reload = browserSync.reload, | |
changed = require('gulp-changed'), | |
sass = require('gulp-sass'), | |
concat = require('gulp-concat'), | |
uglify = require('gulp-uglify'), | |
plumber = require('gulp-plumber'), | |
imagemin = require('gulp-imagemin'), | |
pngquant = require('imagemin-pngquant'), | |
prefix = require('gulp-autoprefixer'), | |
gutil = require('gulp-util'), | |
compass = require('compass-importer'), | |
webpack = require('webpack-stream'), | |
browserify = require('gulp-browserify'), | |
rename = require("gulp-rename"), | |
entorno, | |
locals; | |
gulp.task('clear', function (done) { | |
cache.clearAll(done); | |
}); | |
function onError(error) { | |
gutil.log(error); | |
this.emit('end'); | |
} | |
gulp.task('javascript', function () { | |
gulp.src('./frontend/js/app.js') | |
.pipe(browserify({ transform: ['vueify', 'babelify', 'aliasify'] })) | |
.pipe(plumber()) | |
.pipe(changed('./js/')) | |
// .pipe(webpack({ | |
// watch: true, | |
// output: { | |
// filename: 'bundle.js' | |
// } | |
// })) | |
.pipe(rename('bundle.js')) | |
.pipe(entorno ? uglify({ compress: { drop_console: true } }) : gutil.noop()) | |
.pipe(gulp.dest('./js/')) | |
.pipe(browserSync.reload({ stream: true })); | |
}); | |
gulp.task('sass', function () { | |
gulp.src('frontend/sass/*.scss') | |
.pipe(plumber()) | |
.pipe(sass({ | |
importer: compass | |
})) | |
.pipe(entorno ? sass({ outputStyle: 'compressed' }) : gutil.noop()) | |
.pipe(prefix({ browsers: ['last 2 versions', 'ie 8', 'ie 9', '> 1%', 'Firefox >= 20', 'Opera 12.1', 'iOS 7'], cascade: false })) | |
.pipe(gulp.dest('./css/')) | |
.pipe(browserSync.reload({ stream: true })); | |
}); | |
gulp.task('images', function () { | |
gulp.src('./frontend/images/*.{png,jpg,jpeg,gif,svg}') | |
.pipe(imagemin({ | |
progressive: true, | |
interlaced: true, | |
optimizationLevel: 3, | |
svgoPlugins: [{ | |
removeViewBox: false | |
}], | |
use: [pngquant({ | |
quality: '75-80', | |
speed: 4 | |
})] | |
})) | |
.pipe(gulp.dest('./images/')); | |
}); | |
gulp.task('plugins', function () { | |
gulp.src( | |
[ | |
'./frontend/js/plugins/jquery-2.1.4.js', | |
'./frontend/js/plugins/amplitude.js', | |
'./frontend/js/plugins/classList.min.js',//Le damos soporte a classList | |
'./frontend/js/plugins/owl.carousel.min.js', | |
'./frontend/js/plugins/jquery.validate.js', | |
'./frontend/js/plugins/jquery.alphanum.js' | |
] | |
) | |
.pipe(concat('vendor_all.js')) | |
.pipe(uglify({ | |
compress: { | |
drop_console: true | |
} | |
})) | |
.pipe(gulp.dest('./js/vendor')) | |
.pipe(browserSync.reload({ stream: true })); | |
}); | |
gulp.task('watch', function () { | |
gulp.watch('./frontend/sass/**/*.scss', ['sass']); | |
gulp.watch('./frontend/js/**/*.vue', ['javascript']); | |
gulp.watch('./frontend/js/**/*.js', ['javascript']); | |
gulp.watch('./frontend/js/plugins/*.js', ['plugins']); | |
gulp.watch('./frontend/images/**/*.*', ['images']); | |
}); | |
// Static server | |
gulp.task('serve', function () { | |
var files = [ | |
'./css/style.css', | |
'./js/bundle.js', | |
'./*.php', | |
'./*/*.php' | |
]; | |
//initialize browsersync | |
browserSync.init(files, { | |
//browsersync with a php server | |
open: false, | |
port: 4000, | |
proxy: "http://127.0.0.1:7000", | |
notify: true | |
}); | |
}); | |
gulp.task('set-prod-env', function () { | |
entorno = process.env.NODE_ENV = 'prod'; | |
}); | |
var taskProd = [ | |
'set-prod-env', | |
'serve', | |
'sass', | |
'javascript', | |
'plugins', | |
'images' | |
]; | |
var taskDefault = [ | |
'serve', | |
'sass', | |
'javascript', | |
'plugins', | |
'images', | |
'watch', | |
'clear' | |
]; | |
gulp.task('default', taskDefault); | |
gulp.task('prod', taskProd); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment