-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
200 lines (148 loc) · 5.11 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
var gulp = require('gulp');
var gutil = require('gulp-util');
var gulp = require('gulp');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var source = require('vinyl-source-stream');
var streamify = require('gulp-streamify');
var uglifycss = require('gulp-uglifycss');
var reactify = require('reactify');
var babelify = require('babelify');
var browserify = require('browserify');
var argv = require('yargs').argv;
var server = require('gulp-server-livereload');
var livereload = require('gulp-livereload');
var envify = require('envify');
var gulpsync = require('gulp-sync')(gulp);
var watch = require('gulp-watch');
function notify(error) {
var message = 'In: ';
var title = 'Error: ';
if (error.description) {
title += error.description;
} else if (error.message) {
title += error.message;
}
if (error.filename) {
var file = error.filename.split('/');
message += file[file.length - 1];
}
if (error.lineNumber) {
message += '\nOn Line: ' + error.lineNumber;
}
console.log(error);
}
var mainApp = {};
mainApp.treeLocation = '/jsapp/';
mainApp.sourceBase = './src/main/resources/' + mainApp.treeLocation;
var buildDir = mainApp.sourceBase+'public_html/build';
var pageURL = 'http://127.0.0.1:8080';
var srcDir = mainApp.sourceBase +"src/";
var SASS_FILES = srcDir + '/sass/**/*.scss';
var WATCH_JS = [srcDir +'/react/**/*.js',srcDir+'/app.js'];
var HTML_FILES = [mainApp.sourceBase+"public_html/index.html"];
var cssAssetsLocation = mainApp.sourceBase +"css/**/*";
var imagesLocation = mainApp.sourceBase +"user_images/**/*";
//argv.dir is full path to target folder
mainApp.targetWebappFolder = argv.dir + mainApp.treeLocation;
function mainAppBundle() {
var mainAppBundler = browserify({
entries: [srcDir + 'app.js'],
transform: [["babelify", {"presets": ["es2015", "react"]}], ["envify", {NODE_ENV: 'production', 'global': true, '_': 'purge', }]],
extensions: ['.js'],
debug: false,
cache: {},
packageCache: {},
fullPaths: true
});
return mainAppBundler
.bundle()
.on('error', notify);
}
gulp.task('build-main-app', function () {
mainAppBundle()
.pipe(source('main_app.min.js'))
.pipe(streamify(uglify()))
.pipe(gulp.dest(mainApp.targetWebappFolder));
});
gulp.task('sass-main-app', function () {
gulp.src(SASS_FILES)
.pipe(sass().on('error', sass.logError))
.pipe(concat('main_app_style.css'))
.pipe(gulp.dest(mainApp.targetWebappFolder));
});
gulp.task('copy-css-assets', function () {
gulp.src(cssAssetsLocation)
.pipe(gulp.dest(mainApp.targetWebappFolder));
});
gulp.task('copy-images', function () {
gulp.src(imagesLocation)
.pipe(gulp.dest(mainApp.targetWebappFolder+"images/user_images"));
});
gulp.task('default', ['build-main-app', 'sass-main-app','copy-css-assets','copy-images']);
///////////////////development////////////////////////////
var sassProcess =
function () {
return gulp.src(SASS_FILES)
.pipe(sass().on('error', sass.logError))
.pipe(concat('style.css'))
.pipe(gulp.dest(buildDir+"/css"));
};
gulp.task('build-js', function () {
function devBundle() {
var devBundler = browserify({
entries: [srcDir + 'app.js'],
transform: [["babelify", {"presets": ["es2015", "react"]}]],
extensions: ['.js'],
debug: true,
cache: {},
packageCache: {},
fullPaths: true
});
return devBundler
.bundle()
.on('error', notify);
}
devBundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest(buildDir))
.on('finish', function ( ) {
gutil.log("build bundle end");
livereload.reload(pageURL);
});
});
gulp.task('watch', function () {
watch(SASS_FILES, function (events, done) {
sassProcess()
.on('finish', function ( ) {
gutil.log("processing change in css");
livereload.reload(pageURL);
});
});
watch(WATCH_JS, function (events, done) {
gulp.start('build-js');
});
watch(HTML_FILES, function (events, done) {
gutil.log("starting html change");
livereload.reload(pageURL);
});
});
gulp.task('serve', function (done) {
// livereload.listen();
gulp.src(mainApp.sourceBase+'public_html').on('error', gutil.log)
.pipe(server({
livereload: {
enable: true
},
host: '127.0.0.1',
port: 8080,
defaultFile: 'index.html',
directoryListing: false,
open: true
}));
});
gulp.task('dev', gulpsync.sync(['build-js','watch', 'serve']),function(done)
{
console.log("finished dev")
});