-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
112 lines (95 loc) · 3.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
100
101
102
103
104
105
106
107
108
109
110
111
112
const gulp = require('gulp')
// const concat = require('gulp-concat')
// const uglify = require('gulp-uglify')
const sourcemaps = require('gulp-sourcemaps')
const gutil = require('gulp-util')
const shell = require('gulp-shell')
const clean = require('gulp-clean')
const runSequence = require('run-sequence')
const jscpd = require('gulp-jscpd')
const plumber = require('gulp-plumber')
const notify = require('gulp-notify')
const watch = require('gulp-watch')
const webpack = require('webpack')
const WebpackDevServer = require('webpack-dev-server')
const stream = require('webpack-stream')
const webpackConfig = require('./webpack.config.prod.js')
const webpackDevConfig = require('./webpack.config.dev.js')
const path = {
HTML: 'app/index.html',
ALL: ['app/**/*.js'],
MINIFIED_OUT: 'build.min.js',
DEST_SRC: 'dist/src',
DEST_BUILD: 'dist/build',
DEST: 'dist',
TESTS: './tests/**/*.js'
}
gulp.task('jscpd', () => gulp.src('app/*')
.pipe(jscpd({
languages: ['javascript, css'],
verbose: true
}))
)
gulp.task('clean', () => gulp.src(path.DEST_BUILD,
{
read: false
}
).pipe(clean()))
gulp.task('webpack', [], () =>
// gulp looks for all source files under specified path
gulp.src(path.ALL)
// creates a source map which would be very helpful for debugging
// by maintaining the actual source code structure
.pipe(sourcemaps.init())
// blend in the webpack config into the source files
.pipe(stream(webpackConfig))
// minifies the code for better compression
// .pipe(ignore.exclude([ "**/*.map" ]))
// .pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest(path.DEST_BUILD))
)
// function can use callback
gulp.task('webpack-dev-server', () => {
// Start a webpack-dev-server
new WebpackDevServer(webpack(webpackDevConfig), {
publicPath: '/',
// publicPath: `/ + ${webpackDevConfig.output.publicPath}`,
inline: true,
stats: {
colors: true
}
}).listen(8080, 'localhost', (err) => {
if (err) throw new gutil.PluginError('webpack-dev-server', err)
gutil.log('[webpack-dev-server]', 'http://localhost:8080/webpack-dev-server/index.html')
})
})
gulp.task('test', () => gulp.src('', { read: false })
.pipe(plumber({ errorHandler: notify.onError('Error: <%= error.message %>') }))
.pipe(shell(['npm run local-test'])))
gulp.task('test_watch', () => gulp.src('', { read: false })
.pipe(plumber({ errorHandler: notify.onError('Error: <%= error.message %>') }))
.pipe(shell(['npm run local-test:watch']))
.pipe(shell(['npm run cover'])))
gulp.task('watch_tests', () => {
return watch(path.TESTS, ['test'])
})
gulp.task('watch', () => {
watch(path.ALL.concat(path.TESTS), () => runSequence(['test']))
})
gulp.task('cover', () => gulp.src('', { read: false })
.pipe(plumber({ errorHandler: notify.onError('Error: <%= error.message %>') }))
.pipe(shell(['npm run cover'])))
gulp.task('build', () => {
runSequence(['clean', 'test', 'jscpd'], 'webpack')
})
gulp.task('socket', () => gulp.src('', { read: false })
.pipe(shell(['npm run server']))
)
gulp.task('db', () => gulp.src('', { read: false })
.pipe(shell(['npm run db']))
)
gulp.task('start', () => {
runSequence(['socket'])
})
gulp.task('default', ['socket', 'webpack-dev-server'])