gulpfile.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use strict';
  2. var gulp = require('gulp'),
  3. util = require('util'),
  4. path = require('path'),
  5. immutable = require('immutable'),
  6. gulpWebpack = require('gulp-webpack'),
  7. webpack = require('webpack'),
  8. sourcemaps = require('gulp-sourcemaps'),
  9. exec = require('child_process').execSync,
  10. pwd = exec('pwd').toString();
  11. var plugins = {},
  12. base = immutable.fromJS(require('./webpack.conf.js')),
  13. options = {
  14. prod: base.mergeDeep({
  15. devtool: 'source-map',
  16. plugins: [
  17. new webpack.DefinePlugin({
  18. 'process.env': { NODE_ENV: '"production"' }
  19. }),
  20. new webpack.optimize.UglifyJsPlugin({
  21. sourceMap: true,
  22. compress: {
  23. warnings: false
  24. }
  25. }),
  26. new webpack.ProvidePlugin(plugins)
  27. ],
  28. output: {
  29. filename: 'form.min.js'
  30. }
  31. })
  32. };
  33. var compileJS = function(watch) {
  34. var prodOpts = options.prod.set('watch', watch);
  35. return gulp.src('app/main.js')
  36. .pipe(gulpWebpack(prodOpts.toJS()))
  37. .pipe(gulp.dest('assets/'));
  38. };
  39. gulp.task('js', function() {
  40. compileJS(false);
  41. });
  42. gulp.task('watch', function() {
  43. compileJS(true);
  44. });
  45. gulp.task('all', ['js']);
  46. gulp.task('default', ['all']);