-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
96 lines (85 loc) · 2.9 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
const gulp = require('gulp');
const fs = require('fs');
const path = require('path');
const sass = require('node-sass');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config');
const browserSync = require('browser-sync-webpack-plugin');
const ts_project = require('gulp-typescript').createProject('./src/server/tsconfig.json');
function sassNodeModulesImporter(url, file, done){
// if it starts with a tilde, search in node_modules;
if (url.indexOf('~') === 0){
var nmPath = path.join(__dirname, 'node_modules', url.substring(1)||'');
return done({ file: nmPath });
} else {
return done({ file: url });
}
}
gulp.task('compile_node', function(){
return gulp.src('./src/server/**/*.ts')
.pipe(ts_project()).js
.pipe(gulp.dest('dist/server/'));
});
gulp.task('copy_client_root', ['copy_client_assets'], function(done){
gulp.src('src/client/index.html')
.pipe(gulp.dest('dist/client/'));
sass.render({
file: 'src/client/styles.scss',
outputStyle: 'compressed',
importer: sassNodeModulesImporter
}, function(err, result){
if(err){
throw err;
}
fs.writeFileSync('dist/client/styles.min.css', result.css);
return done();
});
});
gulp.task('copy_client_assets', function(){
return gulp.src(['src/client/assets/**/*'])
.pipe(gulp.dest('dist/client/assets'));
});
gulp.task('copy_fonts', ['copy_client_assets'], function(){
return gulp.src(['node_modules/font-awesome/fonts/*', 'src/client/fonts/*'])
.pipe(gulp.dest('dist/client/fonts'));
});
gulp.task('webpack', function(done) {
let config = webpackConfig;
config.plugins.push(
new webpack.optimize.UglifyJsPlugin()
);
return webpack(config, function(err){
if (err) {
console.log(err);
}
return done(err);
});
});
gulp.task('webpack-watch', function() {
let config = webpackConfig;
config.watch = true;
config.cache = true;
config.bail = false;
config.plugins.push(
new browserSync({
host: 'localhost',
port: 3001,
proxy: 'localhost:3000'
})
);
webpack(config, function(err, stats) {
if (err) {
console.log(err);
}
});
});
gulp.task('copy', ['copy_client_root', 'copy_client_assets', 'copy_fonts']);
gulp.task('watch', ['copy', 'compile_node', 'webpack-watch'], function(){
console.log('watching for changes...');
gulp.watch(['src/client/assets/**/*'], ['copy_client_assets']);
gulp.watch(['src/client/index.html', 'src/client/styles.scss', 'src/client/scss/*.scss'], ['copy_client_root']);
gulp.watch(['node_modules/font-awesome/fonts/*', 'src/client/fonts/*'], ['copy_fonts']);
gulp.watch(['src/server/**/*.ts'], ['compile_node']);
});
// Default Task
gulp.task('default', ['copy', 'compile_node', 'webpack']);