-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
137 lines (118 loc) · 3.8 KB
/
gulpfile.js
File metadata and controls
137 lines (118 loc) · 3.8 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
var gulp = require('gulp'),
browserify = require('browserify'),
babel = require('gulp-babel'),
clean = require('gulp-rimraf'),
es6ify = require('es6ify'),
hbsfy = require('hbsfy'),
source = require('vinyl-source-stream'),
streamify = require('gulp-streamify'),
concat = require('gulp-concat'),
gutil = require('gulp-util'),
livereload = require('gulp-livereload'),
less = require('gulp-less'),
autoprefixer = require('autoprefixer-core'),
postcss = require('gulp-postcss'),
minify = require('gulp-clean-css'),
handlebars = require('gulp-compile-handlebars'),
rename = require('gulp-rename'),
argv = require('yargs').argv,
gulpif = require('gulp-if'),
uglify = require('gulp-uglify'),
server = require('gulp-webserver'),
runsSequence = require('run-sequence'),
plumber = require('gulp-plumber'),
domain = require('domain'),
tap = require('gulp-tap'),
webpack = require('webpack'),
devserver = require('webpack-dev-server'),
gutil = require('gulp-util');
es6ify.traceurOverrides = {experimental: true};
var config = require('./webpack.config.js');
var webpackCompiler = webpack(config);
gulp.task('webpack-scripts', function () {
webpackCompiler.run(function () {
});
});
gulp.task('webpack-dev-server', function () {
return new devserver(webpackCompiler, {
contentBase: "./build",
quiet: true,
inline: true
}).listen(9090, "0.0.0.0", function (err) {
if (err) throw new util.PluginError("webpack-dev-server", err);
});
});
// Convert, prefixize and concat all .less files
gulp.task('stylesheets', function() {
gulp.src('stylesheets/main.less')
.pipe(less())
.on('error', gutil.log)
.pipe(concat('engine.css'))
.pipe(postcss([autoprefixer({
browsers: ['last 2 versions', 'android >= 2.3', '> 1%'],
cascade: false
})]))
// minify css in production
.pipe(gulpif(argv.production, minify()))
.pipe(gulp.dest('build/css'))
.pipe(gulp.dest('lib/css'))
.pipe(gulpif(!argv.production, livereload()))
});
// clean up target folder
gulp.task('clean', function() {
return gulp.src(["build/*", "lib/*"], {read: false})
.pipe(clean());
});
// clean up target lib folder
gulp.task('clean-lib', function() {
return gulp.src(["lib/*"], {read: false})
.pipe(clean());
});
// copy local index file to build folder
gulp.task('html', function () {
return gulp.src('./html/index.hbs')
.pipe(handlebars(
{
show_dev_scripts: !argv.stage,
},
{
batch: [
'./html'
],
helpers: {
getText: function () {
}
}
}))
.pipe(rename('index.html'))
.pipe(gulp.dest("./build"))
.pipe(gulpif(!argv.production, livereload()));
});
// copy local js sources to build folder
gulp.task('vendor', function () {
return gulp.src(['node_modules/3m5-coco/lib/vendor/**'])
.pipe(gulp.dest('./build/js/'))
.pipe(gulpif(!argv.production, livereload()));
});
gulp.task('babel', function() {
return gulp.src('scripts/**/*.js')
.pipe(babel({
presets: ['es2015', 'stage-2', 'stage-3'],
plugins: ['es6-promise']
}))
.pipe(gulp.dest('lib/'));
});
gulp.task('compile', function() {
runsSequence(['clean-lib'], ['babel', 'stylesheets']);
});
gulp.task('webpack-watch', function () {
livereload.listen(10110);
gulp.watch(['stylesheets/**/*.less'], ['stylesheets']);
gulp.watch('html/**/*.hbs', ['html']);
gulp.watch('templates/**/*.hbs', ['html']);
});
gulp.task('serve', ['webpack-watch', 'webpack-dev-server', 'html', 'stylesheets', 'vendor']);
// The default task (called when you run `gulp` from cli)
gulp.task('default', ['serve']);
//maven task, without watcher
gulp.task('maven', ['webpack-scripts', 'stylesheets', 'webpack-scripts', 'vendor', 'html']);