-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
184 lines (163 loc) · 5.07 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
//https://github.com/babel/gulp-babel
const mode = process.env.NODE_ENV || 'development';
const dev = mode === 'development';
const prod = mode === 'production';
var started = false;
//const path = require('path');
//const fs = require('fs');
const gulp = require('gulp');
const del = require('del');
const rename = require('gulp-rename');
const nodemon = require('gulp-nodemon');
const browserSync = require('browser-sync').create();
const svelte = require('rollup-plugin-svelte');
const resolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const rollup = require('gulp-better-rollup');
var frontrollupconfig = {
//input: 'src/main.js',
plugins: [
svelte({
dev: !dev,
css: css => {
css.write('public/bundle.css');
}
}),
resolve(),
commonjs(),
]
}
function frontend_build(done){
return gulp.src('src/client/index.js')
.pipe(rollup(frontrollupconfig, 'umd'))
//.pipe(rollup(require('./rollup.config.js'), 'umd'))
.pipe(rename('bundle.js'))
.pipe(gulp.dest('public/'));
done();
}
exports.frontend_build = frontend_build;
function jscommon_build(){
return gulp.src('src/common/*.js')
//.pipe(rollup(frontrollupconfig, 'umd'))
//.pipe(rename('gunjstrustsharekey.js'))
.pipe(gulp.dest('public/'));
}
exports.jscommon_build = jscommon_build;
//===============================================
//
//===============================================
function backend_build(done){
//return gulp.src('./app.js')
//.pipe(babel({
//presets: ['@babel/preset-env', { modules: false }],
//presets: ['@babel/preset-env'],
//plugins: [
//["add-module-exports"],
//["@babel/plugin-syntax-dynamic-import"]
//]
//}))
//.pipe(rename('backend.js'))
//.pipe(gulp.dest('./'))
done();
}
exports.backend_build = backend_build;
async function cleanbundle(done){
//return gulp.src(['public/bundle.js','public/bundle.js.map'], {read: false, allowEmpty:true})
//.pipe(clean());
//del
del.sync([ 'public/bundle.js','public/bundle.js.map']);
return done();
}
exports.cleanbundle = cleanbundle;
function serve(done){
var stream = nodemon({
//nodemon: require('nodemon'),
script: 'app.js',
//watch:['src/client'],
watch:['public/'],
ext: 'js svelte',
ignore: ['gulpfile.js','node_modules/','data/'],
//tasks: ['cleanscript'],
done: done,
}).on('start', function () {
//console.log('===================================');
//console.log('started!');
// to avoid nodemon being started multiple times
// thanks @matthisk
if (!started) {
done();
started = true;
}
//console.log('started END=========!');
}).on('restart', function () {
//console.log('===================================');
//console.log('restarted!');
//cleanscript();
if(browserSync){
browserSync.reload();
}
}).on('crash', function() {
//console.log('===================================');
console.error('Application has crashed!\n');
stream.emit('restart', 5); // restart the server in 5 seconds
});
return stream;
}
exports.serve = serve;
function refreshbrowser(cb){
browserSync.reload();
return cb();
}
exports.refreshbrowser = refreshbrowser;
function watch(done) {
gulp.watch(['./server.js','./src/server/**/*.*'], gulp.series(backend_build));
//gulp.watch(['./src/client/**/*.*'], gulp.series( cleanbundle, frontrollup_build, refreshbrowser));
gulp.watch(['./src/client/**/*.*'], gulp.series( cleanbundle, frontend_build, copy_html, copy_css));
gulp.watch(['./src/common/**/*.*'], gulp.series( jscommon_build));
return done();
}
exports.watch = watch;
function browser_sync(done){
browserSync.init({
proxy: "localhost:8080"
,files:['pulbic/**/*.*']
//,browser: 'chrome'
//,browser: 'firefox'
});
return done();
}
exports.browser_sync = browser_sync;
function copy_html(){
return gulp.src('src/client/index.html')
.pipe(gulp.dest('public/'));
}
exports.copy_html = copy_html;
function copy_css(){
return gulp.src('src/client/global.css')
.pipe(gulp.dest('public/'));
}
exports.copy_css = copy_css;
function copy_svg(){
return gulp.src('src/client/icons/*.svg')
.pipe(gulp.dest('public/'));
}
exports.copy_svg = copy_svg;
const build = gulp.series(
frontend_build,
backend_build,
copy_css, copy_html,
copy_svg,
watch,
serve,
//browser_sync,
jscommon_build
);
const cleanscript = gulp.series(cleanbundle, frontend_build, jscommon_build);
//const cleanscript = gulp.series(cleanbundle);
exports.cleanscript = cleanscript;
const buildscript = gulp.series( frontend_build, backend_build, copy_css, copy_svg, copy_html, jscommon_build);
exports.buildscript = buildscript;
/*
* Export a default task
*/
exports.default = build;