Last active
October 28, 2017 04:38
-
-
Save eghojansu/47b9775cf81dc2b84e1db4d0fc9ec948 to your computer and use it in GitHub Desktop.
Gulp dev-script
This file contains 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
module.exports = { | |
vendor_js: [ | |
// 'node_modules/path/to/vendor/**/*.js' | |
], | |
vendor_css: [ | |
// 'node_modules/path/to/vendor/**/*.css' | |
], | |
fonts: [ | |
// 'node_modules/**/*.{ttf,woff,woff2,eot,svg}' | |
], | |
scss: [ | |
'app/Resources/scss/**/*.scss' | |
], | |
js: [ | |
'app/Resources/js/**/*.js' | |
] | |
} |
This file contains 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
// optimized for symfony project | |
var path = require('path') | |
var gulp = require('gulp') | |
var concat = require('gulp-concat') | |
var minify = require('gulp-minify') | |
var replace = require('gulp-replace') | |
var sass = require('gulp-sass') | |
var cleanCss = require('gulp-clean-css') | |
var flatten = require('gulp-flatten') | |
var browserSync = require('browser-sync').create() | |
var proxy = 'http://fal.dev/'+path.basename(__dirname)+'/web/app_dev.php' | |
gulp.task('group-js', function() { | |
gulp.src([ | |
'node_modules/jquery/dist/jquery.js', | |
'node_modules/popper.js/dist/umd/popper.js', | |
'node_modules/bootstrap/dist/js/bootstrap.js' | |
]) | |
// .pipe(minify()) | |
.pipe(concat('vendor.js')) | |
.pipe(gulp.dest('web/assets')) | |
.pipe(browserSync.stream()) | |
}) | |
gulp.task('group-css', function() { | |
var urlPattern = /url(?:\(['"]?)(?:.*?)([\w\-\.\?=#&]+?)(?:['"]?\))/g | |
gulp.src([ | |
// 'node_modules/**/*.{ttf,woff,woff2,eot,svg}' | |
]) | |
.pipe(flatten()) | |
.pipe(gulp.dest('web/assets/fonts')) | |
gulp.src([ | |
// 'node_modules/path/to/vendor/**/*.css' | |
]) | |
.pipe(replace(urlPattern, 'url("fonts/$1")')) | |
.pipe(cleanCss()) | |
.pipe(concat('vendor.css')) | |
.pipe(gulp.dest('web/assets')) | |
.pipe(browserSync.stream()) | |
}) | |
gulp.task('style', function() { | |
gulp.src('app/Resources/scss/**/*.scss') | |
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError)) | |
.pipe(gulp.dest('web/assets')) | |
.pipe(browserSync.stream()) | |
}) | |
gulp.task('script', function() { | |
gulp.src('app/Resources/js/**/*.js') | |
.pipe(minify()) | |
.pipe(gulp.dest('web/assets')) | |
.pipe(browserSync.stream()) | |
}) | |
gulp.task('watch', ['style','script','group-js','group-css'], function() { | |
browserSync.init({ | |
proxy: proxy, | |
online: false, | |
ghostMode: false, | |
open: false | |
}) | |
gulp.watch('app/Resources/scss/**/*.scss', ['style']) | |
gulp.watch('app/Resources/js/**/*.js', ['script']) | |
gulp.watch(['app/**/*.yml', 'app/**/*.twig', 'web/*.php', 'src/**/*']).on('change', browserSync.reload) | |
}) | |
gulp.task('default', ['watch']) |
This file contains 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
npm install --save-dev browser-sync gulp gulp-clean-css gulp-concat gulp-flatten gulp-minify gulp-replace gulp-sass |
This file contains 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
{ | |
"name": "appname", | |
"devDependencies": { | |
"browser-sync": "^2.18.7", | |
"gulp": "^3.9.1", | |
"gulp-clean-css": "^3.9.0", | |
"gulp-concat": "^2.6.1", | |
"gulp-flatten": "^0.3.1", | |
"gulp-minify": "^1.0.0", | |
"gulp-replace": "^0.5.4", | |
"gulp-sass": "^3.1.0" | |
}, | |
"dependencies": { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment