gulpfile.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. shell = require('gulp-shell');
  16. var cssProcessors = [
  17. autoprefixer(),
  18. pxtorem({
  19. rootValue: 14,
  20. replace: false,
  21. propWhiteList: []
  22. })
  23. ];
  24. gulp.task('scripts', function() {
  25. browserify('./jet/static/jet/js/src/main.js')
  26. .bundle()
  27. .on('error', function(error) {
  28. console.error(error);
  29. })
  30. .pipe(source('bundle.min.js'))
  31. .pipe(buffer())
  32. .pipe(uglify())
  33. .pipe(gulp.dest('./jet/static/jet/js/build/'));
  34. });
  35. gulp.task('styles', function() {
  36. gulp.src('./jet/static/jet/css/**/*.scss')
  37. .pipe(sourcemaps.init())
  38. .pipe(sass({
  39. outputStyle: 'compressed'
  40. }))
  41. .on('error', function(error) {
  42. console.error(error);
  43. })
  44. .pipe(postcss(cssProcessors))
  45. .on('error', function(error) {
  46. console.error(error);
  47. })
  48. .pipe(sourcemaps.write('./'))
  49. .pipe(gulp.dest('./jet/static/jet/css'));
  50. });
  51. gulp.task('vendor-styles', function() {
  52. merge(
  53. gulp.src([
  54. './node_modules/select2/dist/css/select2.css',
  55. './node_modules/jquery-ui/themes/base/all.css',
  56. './node_modules/timepicker/jquery.ui.timepicker.css'
  57. ]),
  58. gulp.src([
  59. './node_modules/perfect-scrollbar/src/css/main.scss'
  60. ])
  61. .pipe(sass({
  62. outputStyle: 'compressed'
  63. }))
  64. .on('error', function(error) {
  65. console.error(error);
  66. })
  67. )
  68. .pipe(postcss(cssProcessors))
  69. .on('error', function(error) {
  70. console.error(error);
  71. })
  72. .pipe(minifyCss())
  73. .on('error', function(error) {
  74. console.error(error);
  75. })
  76. .pipe(concatCss('vendor.css'))
  77. .on('error', function(error) {
  78. console.error(error);
  79. })
  80. .pipe(gulp.dest('./jet/static/jet/css'));
  81. });
  82. gulp.task('vendor-translations', function() {
  83. gulp.src(['./node_modules/jquery-ui/ui/i18n/*.js'])
  84. .pipe(gulp.dest('./jet/static/jet/js/i18n/jquery-ui/'));
  85. gulp.src(['./node_modules/timepicker/i18n/*.js'])
  86. .pipe(gulp.dest('./jet/static/jet/js/i18n/jquery-ui-timepicker/'));
  87. gulp.src(['./node_modules/select2/dist/js/i18n/*.js'])
  88. .pipe(gulp.dest('./jet/static/jet/js/i18n/select2/'));
  89. });
  90. gulp.task('locales', shell.task('python manage.py compilemessages', { quiet: true }));
  91. gulp.task('build', ['scripts', 'styles', 'vendor-styles', 'vendor-translations', 'locales']);
  92. gulp.task('watch', function() {
  93. gulp.watch('./jet/static/jet/js/src/**/*.js', ['scripts']);
  94. gulp.watch('./jet/static/jet/css/**/*.scss', ['styles']);
  95. gulp.watch(['./jet/locale/**/*.po', './jet/dashboard/locale/**/*.po'], ['locales']);
  96. });
  97. gulp.task('default', ['build', 'watch']);