-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
99 lines (86 loc) · 2.19 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
'use strict';
// gulp plugins
var gulp = require('gulp');
var changed = require('gulp-changed');
var gutil = require('gulp-util');
// misc
var spawn = require('child_process').spawn;
var argv = require('minimist')(process.argv.slice(2));
// webpack
var webpack = require('webpack');
var webpackConfig = require('./webpack.config');
var ngminPlugin = require('ngmin-webpack-plugin');
if (argv.production) {
webpackConfig.plugins = webpackConfig.plugins.concat(
new ngminPlugin(),
new webpack.optimize.UglifyJsPlugin());
webpackConfig.devtool = false;
webpackConfig.debug = false;
}
var ports = {
livereload: 35729
};
var paths = {
other: [
'src/**',
'!src/**/*.js',
'!src/**/*.coffee',
'!src/**/*.scss'
],
distDir: './dist/'
};
gulp.task('webpack', function(cb) {
return webpack(webpackConfig, function(err, stats) {
if (err) {
throw new gutil.PluginError('webpack', err);
}
gutil.log('[webpack]', stats.toString({
colors: true
}));
return cb();
});
});
gulp.task('other', function() {
return gulp.src(paths.other)
.pipe(changed(paths.distDir))
.pipe(gulp.dest(paths.distDir));
});
var rimraf = require('rimraf');
gulp.task('clearTarget', function() {
return rimraf.sync(paths.distDir, gutil.log);
});
gulp.task('build', ['clearTarget', 'webpack', 'other']);
gulp.task('watch', ['clearTarget', 'other'], function() {
var flo, fs, path;
fs = require('fs');
path = require('path');
flo = require('fb-flo');
flo(paths.distDir, {
port: 8889,
host: 'localhost',
verbose: false,
glob: ['**/*.js', '**/*.css', '**/*.html']
}, function(filepath, callback) {
var reload, url;
url = filepath;
reload = true;
if ((path.extname(filepath)) === '.html') {
url = '/';
}
return callback({
resourceURL: url,
contents: fs.readFileSync(paths.distDir + filepath),
reload: reload
});
})
webpack(webpackConfig).watch(200, function(err, stats) {
if (err) {
throw new gutil.PluginError('webpack', err);
}
return gutil.log('[webpack]', stats.toString({
colors: true
}));
});
return gulp.watch(paths.other, ['other']);
});
gulp.task('default', ['build']);