forked from timezoneio/timezoneio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
160 lines (144 loc) · 4.3 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
var gulp = require('gulp');
var gutil = require('gulp-util');
var path = require('path');
var glob = require('glob');
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var plumber = require('gulp-plumber');
var rename = require('gulp-rename');
var transform = require('vinyl-transform');
var uglify = require('gulp-uglify');
var stylus = require('gulp-stylus');
var autoprefixer = require('gulp-autoprefixer');
var cssmin = require('gulp-cssmin');
var rev = require('gulp-rev');
var awspublish = require('gulp-awspublish');
var entries = glob.sync('./app/apps/*.js').reduce(function(obj, path) {
var filename = path.match(/.+\/(\w+).js/)[1];
obj[filename] = path;
return obj;
}, {});
var webpackStats = {
assets: true,
colors: true,
version: true,
modules: false,
hash: false,
timings: false,
chunks: true,
chunkModules: false,
reasons : true,
cached : true,
chunkOrigins : true
};
var webpackConfig = {
entry: entries,
output: {
path: __dirname + '/public',
publicPath: '/',
filename: 'js/bundles/[name].js'
},
resolve: {
extensions: ['', '.json', '.jsx', '.js']
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loaders: ['babel?stage=0'], // optional[]=runtime if needed
},
{ include: /\.json$/, loaders: ["json-loader"] } // moment-timezone
]
},
plugins: [
// Build the production version of React
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production'),
}
}),
// Only include British english in addition to American English for moment.js
new webpack.ContextReplacementPlugin(/moment[\\\/]locale$/, /^\.\/(en-gb)$/)
]
};
var getAWSConfig = function() {
return require('./aws.json');
};
gulp.task('webpack', function(callback) {
webpack(webpackConfig, function(err, stats) {
if(err) throw new gutil.PluginError('webpack', err);
gutil.log('[webpack]', stats.toString(webpackStats));
callback();
});
});
gulp.task('webpack-dev-server', function(callback) {
var devConfig = webpackConfig;
devConfig.devtool = '#inline-source-map';
var compiler = webpack(webpackConfig);
new WebpackDevServer(compiler, {
contentBase: path.join(__dirname, 'public'),
stats: webpackStats,
// hot: true,
// This is where we're running our app server
proxy: {
'*': 'http://localhost:8080'
}
}).listen(8888, function(err) {
if(err) throw new gutil.PluginError('webpack-dev-server error', err);
gutil.log('[webpack-dev-server]', 'http://localhost:8888');
});
});
var getExpires = function() {
var expires = new Date();
expires.setFullYear(expires.getFullYear()+10);
return expires;
};
var s3Headers = {
'Cache-Control': 'max-age=315360000, no-transform, public',
'Expires': getExpires()
};
gulp.task('upload-images', function() {
var publisher = awspublish.create(getAWSConfig());
return gulp.src(['public/images/**/*'])
.pipe(rename(function (path) {
path.dirname = 'images/' + path.dirname;
}))
.pipe(publisher.publish(s3Headers))
.pipe(publisher.cache())
.pipe(awspublish.reporter());
});
gulp.task('upload-css', function() {
var publisher = awspublish.create(getAWSConfig());
return gulp.src(['assets/stylesheets/index.styl'])
.pipe(stylus())
.pipe(autoprefixer({ browsers: ['last 2 versions'] }))
.pipe(cssmin())
.pipe(rename(function (path) {
path.dirname = 'stylesheets/' + path.dirname;
}))
.pipe(rev())
.pipe(awspublish.gzip({ ext: '.gz' }))
.pipe(publisher.publish(s3Headers))
.pipe(publisher.cache())
.pipe(awspublish.reporter())
.pipe(rev.manifest({ merge: true }))
.pipe(gulp.dest('./'));
});
gulp.task('upload-js', ['webpack'], function() {
var publisher = awspublish.create(getAWSConfig());
return gulp.src(['public/js/bundles/*.js'])
.pipe(uglify())
.pipe(rename(function (path) {
path.dirname = 'js/bundles/' + path.dirname;
}))
.pipe(rev())
.pipe(awspublish.gzip({ ext: '.gz' }))
.pipe(publisher.publish(s3Headers))
.pipe(publisher.cache())
.pipe(awspublish.reporter())
.pipe(rev.manifest({ merge: true }))
.pipe(gulp.dest('./'));
});
gulp.task('predeploy', ['webpack', 'upload-images', 'upload-css', 'upload-js']);
gulp.task('default', ['webpack']);