gulpfile-dev.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. module.exports = function(gulp, plugins) {
  2. var argv = require('yargs').argv,
  3. moment = require('moment'),
  4. portfinder = require('portfinder'),
  5. browserSync = require('browser-sync'),
  6. reload = browserSync.reload,
  7. log = console.log;
  8. var that = this;
  9. that.port = +argv.p || undefined;
  10. var pkg = require('../package.json');
  11. var banner = '/*!' + '\n * @project : ' + pkg.name + '\n * @version : ' + pkg.version + '\n * @author : ' + pkg.author + '\n * @update : ' + moment().format('YYYY-MM-DD h:mm:ss a') + '\n */\r';
  12. gulp.task('dev_conn', function() {
  13. portfinder.getPort(function (err, port) {
  14. browserSync({
  15. server: {
  16. baseDir: "src",
  17. directory: true
  18. },
  19. notify: false,
  20. port: that.port||port,
  21. open: "external",
  22. browser: "/Applications/Google\ Chrome.app/"
  23. })
  24. })
  25. })
  26. gulp.task('dev_sass', function() {
  27. var config = {
  28. sourceComments: 'map',
  29. sourceMap: 'sass',
  30. style: 'compact',
  31. onError: function(err){ console.log('...err...: ' + err) }
  32. }
  33. return gulp.src('src/sass/**')
  34. .pipe(plugins.sass(config))
  35. .pipe(plugins.autoprefixer("last 1 version", "> 1%", "ie 8", "ie 7"))
  36. .pipe(gulp.dest('src/css'))
  37. })
  38. gulp.task('dev_css', function() {
  39. return gulp.src('src/css/**')
  40. .pipe(gulp.dest('src/css'))
  41. .pipe(reload({stream:true}))
  42. })
  43. gulp.task('default', ['dev_conn'], function(){
  44. gulp.watch('src/sass/**', ['dev_sass'])
  45. gulp.watch('src/css/**', ['dev_css'])
  46. gulp.watch('src/img/**', reload)
  47. gulp.watch('src/js/**', reload)
  48. })
  49. }