-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
80 lines (72 loc) · 2.18 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
// include gulp
var gulp = require('gulp');
var webpack = require('webpack');
var autoprefixer = require('autoprefixer');
var awspublish = require('gulp-awspublish');
var credentials = require('./credentials.js');
var environment = require('./environment.js');
gulp.task('build', function(cb) {
// FIXME: duplicated code with webpack.config.js
webpack({
entry: [
'./' + environment.APP + '/src/index.jsx' // Your appʼs entry point
],
output: {
path: './' + environment.APP + '/build',
publicPath: '/',
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loaders: ['babel']
},
{
test: /\.css$/,
loader: 'style!css!postcss!'
}
]
},
postcss: [autoprefixer],
resolve: {
extensions: ['', '.js', '.jsx'],
modulesDirectories: ['node_modules', 'components', 'node_modules/bootstrap/dist/css']
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
]
}, function webpackCallback(err, stats) {
cb(err);
});
});
// Publish files to amazon s3
gulp.task('publish', function() {
var publisher = awspublish.create({
region: 'ap-southeast-1',
params: {
Bucket: 'ones.appx.hk'
},
accessKeyId: credentials.AWS_ACCESS_KEY_ID,
secretAccessKey: credentials.AWS_SECRET_ACCESS_KEY
});
// define custom headers
var headers = {
'Cache-Control': 'max-age=8, no-transform, public'
};
return gulp.src(environment.APP + '/build/**/*')
// gzip, Set Content-Encoding headers and add .gz extension
// .pipe($.awspublish.gzip({ ext: '.gz' }))
// publisher will add Content-Length, Content-Type and headers specified above
// If not specified it will set x-amz-acl to public-read by default
.pipe(publisher.publish(headers))
// this will delete old files from the bucket
.pipe(publisher.sync({ whitelistedFiles: ['images/uploads/'] }))
// create a cache file to speed up consecutive uploads
.pipe(publisher.cache())
// print upload updates to console
.pipe(awspublish.reporter());
});