Last active
June 29, 2020 17:06
-
-
Save mikestreety/11402642 to your computer and use it in GitHub Desktop.
advance gulpfile
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
var gulp = require('gulp'); | |
var plugins = require("gulp-load-plugins")({ | |
pattern: ['gulp-*', 'gulp.*'], | |
replaceString: /\bgulp[\-.]/ | |
}); | |
var basePaths = { | |
public: './public/', | |
src: './src/assets/', | |
bower: './bower_components/' | |
} | |
var paths = { | |
styles: { | |
src: basePaths.src + 'sass/*.scss', | |
dest: basePaths.public + 'css/' | |
}, | |
scripts: { | |
src: basePaths.src + 'js/', | |
dest: basePaths.public + 'js/' | |
} | |
} | |
var displayError = function(error) { | |
var errorString = '[' + error.plugin + ']'; | |
errorString += ' ' + error.message.replace("\n",''); | |
if(error.fileName) | |
errorString += ' in ' + error.fileName; | |
if(error.lineNumber) | |
errorString += ' on line ' + error.lineNumber; | |
console.error(errorString); | |
} | |
var changeEvent = function(evt) { | |
console.log( | |
'[watcher] File ' + evt.path.replace(/.*(?=assets)/,'') + ' was ' + evt.type + ', compiling...' | |
); | |
} | |
gulp.task('publish', plugins.shell.task([ | |
'cd ../../../ && php artisan asset:publish bozboz/admin', | |
]) | |
) | |
gulp.task('sass', function (){ | |
gulp.src(paths.styles.src) | |
.pipe(plugins.rubySass({ | |
style: 'compressed', | |
sourcemap: true, | |
precision: 2 | |
})) | |
.on('error', function(err){ | |
displayError(err); | |
}) | |
.pipe(plugins.autoprefixer( | |
'last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4' | |
)) | |
.pipe(gulp.dest(paths.styles.dest)) | |
}); | |
gulp.task('css', ['sass'], function(){ | |
gulp.src([ | |
basePaths.bower + 'bootstrap/dist/css/bootstrap.min.css', | |
basePaths.bower + 'summernote/dist/summernote.css', | |
paths.styles.dest + 'style.css', | |
'../media-library/public/css/media-library.css' // Temporary measure | |
]) | |
.pipe(plugins.concat('admin.min.css')) | |
.pipe(gulp.dest(paths.styles.dest)) | |
}); | |
gulp.task('scripts', function(){ | |
gulp.src([ | |
basePaths.bower + 'jquery/dist/jquery.min.js', | |
basePaths.bower + 'bootstrap/dist/js/bootstrap.min.js', | |
basePaths.bower + 'summernote/dist/summernote.min.js', | |
basePaths.bower + 'jquery-sortable/source/js/jquery-sortable-min.js', | |
basePaths.bower + 'imagesloaded/imagesloaded.pkgd.min.js', | |
basePaths.bower + 'masonry/dist/masonry.pkgd.min.js', | |
paths.scripts.src + 'scripts.js', | |
]) | |
.pipe(plugins.concat('admin.js')) | |
.pipe(gulp.dest(paths.scripts.dest)) | |
.pipe(plugins.rename('admin.min.js')) | |
.pipe(plugins.uglify({outSourceMap: true})) | |
.pipe(gulp.dest(paths.scripts.dest)) | |
}); | |
gulp.task('sprite', function () { | |
var spriteData = gulp.src(paths.sprite.src).pipe(plugins.spritesmith({ | |
imgName: 'sprite.png', | |
cssName: '_sprite.scss', | |
imgPath: '/assets/images/sprite.png', // Gets put in the css | |
cssVarMap: function (sprite) { | |
sprite.name = 'sprite-' + sprite.name; | |
} | |
})); | |
spriteData.img.pipe(gulp.dest(paths.sprite.dest)); | |
spriteData.css.pipe(gulp.dest(paths.styles.src)); | |
}); | |
gulp.task('watch', ['scripts', 'css', 'publish'], function(){ | |
gulp.watch(paths.styles.src, ['css', 'publish']) | |
.on('change', function(evt) { | |
changeEvent(evt) | |
}); | |
gulp.watch(paths.scripts.src + '*.js', ['scripts', 'publish']) | |
.on('change', function(evt) { | |
changeEvent(evt) | |
}); | |
}) | |
gulp.task('default', ['scripts', 'css', 'publish']); |
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
{ | |
"devDependencies": { | |
"gulp": "^3.5.6", | |
"gulp-ruby-sass": "^0.4.0", | |
"gulp-autoprefixer": "0.0.6", | |
"gulp-shell": "^0.2.4", | |
"gulp-concat": "^2.2.0", | |
"gulp-uglify": "^0.2.1", | |
"gulp-rename": "^1.2.0", | |
"gulp-load-plugins": "^0.5.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The solution to include bower is actually smart