gulpfile.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. 'use strict';
  2. var gulp = require('gulp');
  3. var util = require('util');
  4. var path = require('path');
  5. var immutable = require('immutable');
  6. var gulpWebpack = require('gulp-webpack');
  7. var webpack = require('webpack');
  8. var sourcemaps = require('gulp-sourcemaps');
  9. var exec = require('child_process').execSync;
  10. var sass = require('gulp-sass');
  11. var cleancss = require('gulp-clean-css');
  12. var csscomb = require('gulp-csscomb');
  13. var rename = require('gulp-rename');
  14. var autoprefixer = require('gulp-autoprefixer');
  15. var pwd = exec('pwd').toString();
  16. // configure the paths
  17. var watch_dir = './scss/**/*.scss';
  18. var src_dir = './scss/*.scss';
  19. var dest_dir = './assets';
  20. var paths = {
  21. source: src_dir
  22. };
  23. var plugins = {};
  24. var base = immutable.fromJS(require('./webpack.conf.js'));
  25. var options = {
  26. prod: base.mergeDeep({
  27. devtool: 'source-map',
  28. optimization: {minimize: true},
  29. plugins: [
  30. new webpack.DefinePlugin({
  31. 'process.env': { NODE_ENV: '"production"' }
  32. }),
  33. new webpack.ProvidePlugin(plugins)
  34. ],
  35. output: {
  36. filename: 'form.min.js'
  37. }
  38. })
  39. };
  40. // var compileJS = function(watch) {
  41. // var prodOpts = options.prod.set('watch', watch);
  42. //
  43. // return gulp.src('app/main.js')
  44. // .pipe(gulpWebpack(prodOpts.toJS()))
  45. // .pipe(gulp.dest('assets/'));
  46. // };
  47. var compileCSS = function() {
  48. return gulp.src(paths.source)
  49. .pipe(sourcemaps.init())
  50. .pipe(sass({outputStyle: 'compact', precision: 10})
  51. .on('error', sass.logError)
  52. )
  53. .pipe(sourcemaps.write())
  54. .pipe(autoprefixer())
  55. .pipe(gulp.dest(dest_dir))
  56. .pipe(csscomb())
  57. .pipe(cleancss())
  58. .pipe(rename({
  59. suffix: '.min'
  60. }))
  61. .pipe(gulp.dest(dest_dir));
  62. };
  63. // gulp.task('js', function() {
  64. // compileJS(false);
  65. // });
  66. gulp.task('css', function() {
  67. compileCSS();
  68. });
  69. gulp.task('watch', function() {
  70. gulp.watch(watch_dir, ['css']);
  71. // compileJS(true);
  72. });
  73. gulp.task('all', ['css']);
  74. gulp.task('default', ['all']);