-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
145 lines (124 loc) · 3.39 KB
/
gulpfile.js
File metadata and controls
145 lines (124 loc) · 3.39 KB
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
require('dotenv').config();
var debug = process.env.NODE_ENV !== 'production';
var fs = require('fs');
var _ = require('underscore');
var http = require('http');
var https = require('https');
var path = require('path');
var gulp = require('gulp');
var sass = require('gulp-sass');
var cleanCSS = require('gulp-clean-css');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var rimraf = require('gulp-rimraf');
var concat = require('gulp-concat');
var babel = require('gulp-babel');
var notify = require('gulp-notify');
var gutil = require('gulp-util');
var request = require('request');
var buffer = require('vinyl-buffer');
var reactify = require('reactify');
var history = require('connect-history-api-fallback');
var request = require('superagent');
var open = require('open');
var parser = require('xml2json');
//
// Webpack
//
var WebpackDevServer = require('webpack-dev-server');
var webpack = require('webpack');
var webpackConfigDevelopment = require('./webpack.config.js');
var webpackConfigStaging = require('./webpack.config.staging.js');
var webpackConfigProduction = require('./webpack.config.production.js');
var getSitemap = require('./src/server/get-sitemap.js');
var port = debug ? 5319 : 8080;
//
// Default tasks
//
var tasks = [
'sitemap',
'build:css',
'build:dev',
];
gulp.task('sitemap', getSitemap)
gulp.task('build:css', function () {
var fileType = 'CSS';
return gulp.src('./scss/**/*.scss')
.pipe(sass({
errLogToConsole: true,
includePaths: [
'./node_modules/'
]
}))
.on('error', notify.onError(function (error) {
return console.error('CSS ', error);
}))
.pipe(autoprefixer())
.pipe(cleanCSS({
debug: debug
}, (details) => {
console.log(`${details.name}: ${details.stats.originalSize}`);
console.log(`${details.name}: ${details.stats.minifiedSize}`);
}))
.pipe(gulp.dest('./public/css'));
});
//
// Staging build
//
gulp.task('build:staging', [ 'sitemap', 'build:css' ], function (callback) {
// run webpack
webpack(webpackConfigStaging, function (err, stats) {
if (err) throw new gutil.PluginError('webpack:build', err);
gutil.log('[webpack:build]', stats.toString({
colors: true
}));
callback();
});
});
//
// Production build
//
gulp.task('build:prod', [ 'sitemap', 'build:css' ], function (callback) {
// run webpack
webpack(webpackConfigProduction, function (err, stats) {
if (err) throw new gutil.PluginError('webpack:build', err);
gutil.log('[webpack:build]', stats.toString({
colors: true
}));
callback();
});
});
//
// Development build
//
gulp.task('build:dev', function (callback) {
// run webpack
webpack(webpackConfigDevelopment, function (err, stats) {
if (err) throw new gutil.PluginError('webpack:build:dev', err);
gutil.log('[webpack:build:dev]', stats.toString({
colors: true
}));
callback();
});
});
gulp.task('watch', tasks, function () {
gutil.log('[express:server]', 'http://localhost:' + port);
gulp.watch('./scss/**/*.scss', [ 'build:css' ], { verbose: true }, function () {
if (process.send) {
process.send({
event:'online',
url:`http://localhost:${process.env.PORT}`
})
}
});
gulp.watch([ './src/**/*' ], [ 'build:dev' ], { verbose: true }, function () {
if (process.send) {
process.send({
event:'online',
url:`http://localhost:${process.env.PORT}`
})
}
});
// open('http://localhost:' + port);
})
gulp.task('default', tasks);