gulpfile.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. return 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. return 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. return merge(
  54. gulp.src('./node_modules/jquery-ui/themes/base/images/*')
  55. .pipe(gulp.dest('./jet/static/jet/css/jquery-ui/images/')),
  56. merge(
  57. gulp.src([
  58. './node_modules/select2/dist/css/select2.css',
  59. './node_modules/timepicker/jquery.ui.timepicker.css'
  60. ]),
  61. gulp.src([
  62. './node_modules/jquery-ui/themes/base/all.css'
  63. ])
  64. .pipe(cleanCSS()) // needed to remove jQuery UI comments breaking concatCss
  65. .on('error', function(error) {
  66. console.error(error);
  67. })
  68. .pipe(concatCss('jquery-ui.css', {
  69. rebaseUrls: false
  70. }))
  71. .on('error', function(error) {
  72. console.error(error);
  73. })
  74. .pipe(replace('images/', 'jquery-ui/images/'))
  75. .on('error', function(error) {
  76. console.error(error);
  77. }),
  78. gulp.src([
  79. './node_modules/perfect-scrollbar/src/css/main.scss'
  80. ])
  81. .pipe(sass({
  82. outputStyle: 'compressed'
  83. }))
  84. .on('error', function(error) {
  85. console.error(error);
  86. })
  87. )
  88. .pipe(postcss(cssProcessors))
  89. .on('error', function(error) {
  90. console.error(error);
  91. })
  92. .pipe(concatCss('vendor.css', {
  93. rebaseUrls: false
  94. }))
  95. .on('error', function(error) {
  96. console.error(error);
  97. })
  98. .pipe(cleanCSS())
  99. .on('error', function(error) {
  100. console.error(error);
  101. })
  102. .pipe(gulp.dest('./jet/static/jet/css'))
  103. )
  104. });
  105. gulp.task('vendor-translations', function() {
  106. return merge(
  107. gulp.src(['./node_modules/jquery-ui/ui/i18n/*.js'])
  108. .pipe(gulp.dest('./jet/static/jet/js/i18n/jquery-ui/')),
  109. gulp.src(['./node_modules/timepicker/i18n/*.js'])
  110. .pipe(gulp.dest('./jet/static/jet/js/i18n/jquery-ui-timepicker/')),
  111. gulp.src(['./node_modules/select2/dist/js/i18n/*.js'])
  112. .pipe(gulp.dest('./jet/static/jet/js/i18n/select2/'))
  113. )
  114. });
  115. gulp.task('locales', shell.task('python manage.py compilemessages', { quiet: true }));
  116. gulp.task('build', ['scripts', 'styles', 'vendor-styles', 'vendor-translations', 'locales']);
  117. gulp.task('watch', function() {
  118. gulp.watch('./jet/static/jet/js/src/**/*.js', ['scripts']);
  119. gulp.watch('./jet/static/jet/css/**/*.scss', ['styles']);
  120. gulp.watch(['./jet/locale/**/*.po', './jet/dashboard/locale/**/*.po'], ['locales']);
  121. });
  122. gulp.task('default', ['build', 'watch']);