gulpfile.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. require('es6-promise').polyfill();
  2. var gulp = require('gulp'),
  3. browserify = require('browserify'),
  4. concatCss = require('gulp-concat-css'),
  5. cleanCSS = require('gulp-clean-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. replace = require('gulp-replace');
  17. var cssProcessors = [
  18. autoprefixer(),
  19. pxtorem({
  20. rootValue: 14,
  21. replace: false,
  22. propWhiteList: []
  23. })
  24. ];
  25. gulp.task('scripts', function() {
  26. browserify('./jet/static/jet/js/src/main.js')
  27. .bundle()
  28. .on('error', function(error) {
  29. console.error(error);
  30. })
  31. .pipe(source('bundle.min.js'))
  32. .pipe(buffer())
  33. .pipe(uglify())
  34. .pipe(gulp.dest('./jet/static/jet/js/build/'));
  35. });
  36. gulp.task('styles', function() {
  37. gulp.src('./jet/static/jet/css/**/*.scss')
  38. .pipe(sourcemaps.init())
  39. .pipe(sass({
  40. outputStyle: 'compressed'
  41. }))
  42. .on('error', function(error) {
  43. console.error(error);
  44. })
  45. .pipe(postcss(cssProcessors))
  46. .on('error', function(error) {
  47. console.error(error);
  48. })
  49. .pipe(sourcemaps.write('./'))
  50. .pipe(gulp.dest('./jet/static/jet/css'));
  51. });
  52. gulp.task('vendor-styles', function() {
  53. gulp.src('./node_modules/jquery-ui/themes/base/images/*')
  54. .pipe(gulp.dest('./jet/static/jet/css/jquery-ui/images/'));
  55. merge(
  56. gulp.src([
  57. './node_modules/select2/dist/css/select2.css',
  58. './node_modules/timepicker/jquery.ui.timepicker.css'
  59. ]),
  60. gulp.src([
  61. './node_modules/jquery-ui/themes/base/all.css'
  62. ])
  63. .pipe(cleanCSS()) // needed to remove jQuery UI comments breaking concatCss
  64. .on('error', function(error) {
  65. console.error(error);
  66. })
  67. .pipe(concatCss('jquery-ui.css', {
  68. rebaseUrls: false
  69. }))
  70. .on('error', function(error) {
  71. console.error(error);
  72. })
  73. .pipe(replace('images/', 'jquery-ui/images/'))
  74. .on('error', function(error) {
  75. console.error(error);
  76. }),
  77. gulp.src([
  78. './node_modules/perfect-scrollbar/src/css/main.scss'
  79. ])
  80. .pipe(sass({
  81. outputStyle: 'compressed'
  82. }))
  83. .on('error', function(error) {
  84. console.error(error);
  85. })
  86. )
  87. .pipe(postcss(cssProcessors))
  88. .on('error', function(error) {
  89. console.error(error);
  90. })
  91. .pipe(concatCss('vendor.css', {
  92. rebaseUrls: false
  93. }))
  94. .on('error', function(error) {
  95. console.error(error);
  96. })
  97. .pipe(cleanCSS())
  98. .on('error', function(error) {
  99. console.error(error);
  100. })
  101. .pipe(gulp.dest('./jet/static/jet/css'));
  102. });
  103. gulp.task('vendor-translations', function() {
  104. gulp.src(['./node_modules/jquery-ui/ui/i18n/*.js'])
  105. .pipe(gulp.dest('./jet/static/jet/js/i18n/jquery-ui/'));
  106. gulp.src(['./node_modules/timepicker/i18n/*.js'])
  107. .pipe(gulp.dest('./jet/static/jet/js/i18n/jquery-ui-timepicker/'));
  108. gulp.src(['./node_modules/select2/dist/js/i18n/*.js'])
  109. .pipe(gulp.dest('./jet/static/jet/js/i18n/select2/'));
  110. });
  111. gulp.task('locales', shell.task('python manage.py compilemessages', { quiet: true }));
  112. gulp.task('build', ['scripts', 'styles', 'vendor-styles', 'vendor-translations', 'locales']);
  113. gulp.task('watch', function() {
  114. gulp.watch('./jet/static/jet/js/src/**/*.js', ['scripts']);
  115. gulp.watch('./jet/static/jet/css/**/*.scss', ['styles']);
  116. gulp.watch(['./jet/locale/**/*.po', './jet/dashboard/locale/**/*.po'], ['locales']);
  117. });
  118. gulp.task('default', ['build', 'watch']);