Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / build-scripts / gulpfile-clientapp.js
blob536f68fa2d8fb324621c6d8cecf42db124b5c2f8
1 'use strict';
3 var gulp = require('gulp');
4 var gutil = require('gulp-util');
5 var sourcemaps = require('gulp-sourcemaps');
6 var webpack = require('webpack-stream');
7 var uglify = require('gulp-uglify');
8 var restoreTimestamps = require('./gulp-restore-timestamps');
9 var getSourceMapOptions = require('./get-sourcemap-options');
11 /**
12 * Hook into the compile stage
14 gulp.task('clientapp:compile', ['clientapp:compile:copy-files', 'clientapp:compile:webpack']);
16 /**
17 * Hook into the post-compile stage
19 gulp.task('clientapp:post-compile', ['clientapp:post-compile:uglify']);
21 gulp.task('clientapp:compile:copy-files', function() {
22 return gulp
23 .src(['public/fonts/**', 'public/images/**', 'public/sprites/**', 'public/repo/**'], {
24 base: './public',
25 stat: true
27 .pipe(gulp.dest('output/assets'))
28 .pipe(restoreTimestamps());
29 });
31 gulp.task('clientapp:compile:webpack-server', ['clientapp:compile:copy-files'], function() {
32 return gulp
33 .src('./public/js/webpack.server.config')
34 .pipe(webpack(require('../public/js/webpack.server.config')))
35 .pipe(gulp.dest('output/assets/js'));
36 });
38 gulp.task(
39 'clientapp:compile:webpack',
40 ['clientapp:compile:copy-files', 'clientapp:compile:webpack-server'],
41 function() {
42 return gulp
43 .src('./public/js/webpack.config')
44 .pipe(webpack(require('../public/js/webpack.config')))
45 .pipe(gulp.dest('output/assets/js'));
49 function getUglifyOptions() {
50 if (process.env.FAST_UGLIFY && JSON.parse(process.env.FAST_UGLIFY)) {
51 gutil.log('Using fast uglify. The resulting javascript artifacts will be much bigger');
52 return {
53 mangle: false,
54 compress: false
59 gulp.task('clientapp:post-compile:uglify', function() {
60 var sourceMapOpts = getSourceMapOptions();
61 return gulp
62 .src('output/assets/js/*.js')
63 .pipe(
64 sourcemaps.init({
65 /* loadMaps: true */
68 .pipe(uglify(getUglifyOptions()))
69 .pipe(sourcemaps.write(sourceMapOpts.dest, sourceMapOpts.options))
70 .pipe(gulp.dest('output/assets/js'));
71 });