-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
130 lines (114 loc) · 2.84 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
var gulp = require('gulp');
var webpack = require('webpack');
var path = require('path');
var fs = require('fs');
var DeepMerge = require('deep-merge');
var nodemon = require('nodemon');
var deepmerge = DeepMerge(function(target, source, key) {
if(target instanceof Array) {
return [].concat(target, source);
}
return source;
});
// generic
var defaultConfig = {};
if(process.env.NODE_ENV !== 'production') {
defaultConfig.debug = true;
}
function config(overrides) {
return deepmerge(defaultConfig, overrides || {});
}
// frontend
var frontendConfig = config({
entry: {
index : __dirname + '/public/js/index.js',
maps : __dirname + '/public/js/maps.js',
aggregation : __dirname + '/public/js/aggregation.js',
bootstrap : __dirname + '/public/js/bootstrapStatic.js'
},
output: {
path: path.join(__dirname, './public/dist/js'),
filename: '[name].js'
},
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['es2015', 'react']
},
},
{ test: /\.css$/, loader: "style-loader!css-loader" },
{ test: /\.png$/, loader: "url-loader", query: { mimetype: "image/png" }}
]
},
});
//backend
var nodeModules = {};
fs.readdirSync('node_modules')
.filter(function(x) {
return ['.bin'].indexOf(x) === -1;
})
.forEach(function(mod) {
nodeModules[mod] = 'commonjs ' + mod;
});
var backendConfig = config({
entry: './routes/index.js',
output: {
path: path.join(__dirname, './public/dist/js'),
filename: '[name].js'
},
node: {
__dirname: true,
__filename: true
},
externals: nodeModules,
plugins: [
new webpack.IgnorePlugin(/\.(css|less)$/),
new webpack.BannerPlugin('require("source-map-support").install();',
{ raw: true, entryOnly: false })
]
});
// tasks
function onBuild(done) {
return function(err, stats) {
if(err) {
console.log('Error', err);
}
if(done) {
done();
}
}
}
gulp.task('frontend-build', function(done) {
webpack(frontendConfig).run(onBuild(done));
});
gulp.task('frontend-watch', function() {
webpack(frontendConfig).watch(100, onBuild());
});
gulp.task('backend-build', function(done) {
webpack(backendConfig).run(onBuild(done));
});
gulp.task('backend-watch', function() {
webpack(backendConfig).watch(100, function(err, stats) {
onBuild()(err, stats);
nodemon.restart();
});
});
gulp.task('build', ['frontend-build', 'backend-build']);
gulp.task('watch', ['run']);
gulp.task('run', ['frontend-watch', 'backend-watch'], function() {
nodemon({
execMap: {
js: 'node'
},
script: 'app.js',
ignore: ['*'],
watch: ['public/dist/js/'],
ext: 'noop'
}).on('restart', function() {
console.log('Server started. Listening @ http://localhost:3000');
});
});