gulpfile.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. require('es6-promise').polyfill();
  2. var gulp = require('gulp'),
  3. browserify = require('browserify'),
  4. concatCss = require('gulp-concat-css'),
  5. minifyCss = require('gulp-minify-css'),
  6. sass = require('gulp-sass'),
  7. uglify = require('gulp-uglify'),
  8. buffer = require('vinyl-buffer'),
  9. source = require('vinyl-source-stream'),
  10. sourcemaps = require('gulp-sourcemaps'),
  11. merge = require('merge-stream'),
  12. postcss = require('gulp-postcss'),
  13. pxtorem = require('postcss-pxtorem'),
  14. autoprefixer = require('autoprefixer');
  15. var cssProcessors = [
  16. autoprefixer(),
  17. pxtorem({
  18. rootValue: 14,
  19. replace: false,
  20. propWhiteList: []
  21. })
  22. ];
  23. gulp.task('scripts', function() {
  24. browserify('./jet/static/jet/js/src/main.js')
  25. .bundle()
  26. .on('error', function(error) {
  27. console.error(error);
  28. })
  29. .pipe(source('bundle.min.js'))
  30. .pipe(buffer())
  31. .pipe(uglify())
  32. .pipe(gulp.dest('./jet/static/jet/js/build/'));
  33. });
  34. gulp.task('styles', function() {
  35. gulp.src('./jet/static/jet/css/**/*.scss')
  36. .pipe(sourcemaps.init())
  37. .pipe(sass({
  38. outputStyle: 'compressed'
  39. }))
  40. .on('error', function(error) {
  41. console.error(error);
  42. })
  43. .pipe(postcss(cssProcessors))
  44. .on('error', function(error) {
  45. console.error(error);
  46. })
  47. .pipe(sourcemaps.write('./'))
  48. .pipe(gulp.dest('./jet/static/jet/css'));
  49. });
  50. gulp.task('vendor-styles', function() {
  51. merge(
  52. gulp.src([
  53. './node_modules/select2/dist/css/select2.css',
  54. './node_modules/jquery-ui/themes/base/all.css',
  55. './node_modules/timepicker/jquery.ui.timepicker.css'
  56. ]),
  57. gulp.src([
  58. './node_modules/perfect-scrollbar/src/css/main.scss'
  59. ])
  60. .pipe(sass({
  61. outputStyle: 'compressed'
  62. }))
  63. .on('error', function(error) {
  64. console.error(error);
  65. })
  66. )
  67. .pipe(postcss(cssProcessors))
  68. .on('error', function(error) {
  69. console.error(error);
  70. })
  71. .pipe(minifyCss())
  72. .on('error', function(error) {
  73. console.error(error);
  74. })
  75. .pipe(concatCss('vendor.css'))
  76. .on('error', function(error) {
  77. console.error(error);
  78. })
  79. .pipe(gulp.dest('./jet/static/jet/css'));
  80. });
  81. gulp.task('vendor-translations', function() {
  82. gulp.src(['./node_modules/jquery-ui/ui/i18n/*.js'])
  83. .pipe(gulp.dest('./jet/static/jet/js/i18n/jquery-ui/'));
  84. gulp.src(['./node_modules/timepicker/i18n/*.js'])
  85. .pipe(gulp.dest('./jet/static/jet/js/i18n/jquery-ui-timepicker/'));
  86. gulp.src(['./node_modules/select2/dist/js/i18n/*.js'])
  87. .pipe(gulp.dest('./jet/static/jet/js/i18n/select2/'));
  88. });
  89. gulp.task('build', ['scripts', 'styles', 'vendor-styles', 'vendor-translations']);
  90. gulp.task('watch', function() {
  91. gulp.watch('./jet/static/jet/js/src/**/*.js', ['scripts']);
  92. gulp.watch('./jet/static/jet/css/**/*.scss', ['styles']);
  93. });
  94. gulp.task('default', ['build', 'watch']);