-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
110 lines (95 loc) · 2.74 KB
/
gulpfile.babel.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
const gulp = require('gulp');
const babel = require('gulp-babel');
const mocha = require('gulp-mocha-co');
const csso = require('gulp-csso');
const sass = require('gulp-sass');
const imagemin = require('gulp-imagemin');
const eslint = require('gulp-eslint');
const nodemon = require('nodemon');
const webpack = require('webpack-stream');
const path = require('path');
const runSequence = require('run-sequence');
const packageJson = require('./package.json');
const swPrecache = require('sw-precache');
const rootDir = './public';
const env = require('./config/connections').env;
const webpackConfig = (env === 'production') ?
require('./webpack.prod.config.js') : require('./webpack.dev.config.js');
require('babel-core/register');
require('babel-polyfill');
function writeServiceWorker(dir, handleFetch, cb) {
const config = {
cacheId: packageJson.name,
handleFetch: true,
staticFileGlobs: [
`${dir}/index.html`,
`${dir}/app.js`,
`${dir}/resources/style/main.css`,
`${dir}/resources/images/menu.svg`,
],
stripPrefix: `${dir}/`,
verbose: true,
};
swPrecache.write(path.join(dir, 'service-worker.js'), config, cb);
}
gulp.task('fonts', () =>
gulp.src('./app/resources/Fonts/**/*.+(otf|ttf|eof|ttc|woff)')
.pipe(gulp.dest(`${rootDir}/resources/Fonts/`))
);
gulp.task('css', () =>
gulp.src('./app/resources/style/**/*.scss')
.pipe(
sass({
includePaths: ['./app/resources/style'],
errLogToConsole: true,
}))
.pipe(csso())
.pipe(gulp.dest(`${rootDir}/resources/style/`))
);
gulp.task('html', () =>
gulp.src('./app/*.html')
.pipe(gulp.dest(rootDir))
);
gulp.task('image', () =>
gulp.src('./app/resources/images/**/*.+(png|jpg|svg)')
.pipe(imagemin())
.pipe(gulp.dest(`${rootDir}/resources/images/`))
);
gulp.task('watch', (cb) => {
gulp.watch('./app/resources/style/**/*.scss', ['css']);
gulp.watch('./app/*.html', ['html']);
gulp.watch('./app/**/*.js', ['bundle']);
cb();
});
gulp.task('bundle', () =>
gulp.src('./app/app.js')
.pipe(webpack(webpackConfig))
.pipe(gulp.dest(rootDir))
);
gulp.task('test', () =>
gulp.src('tests/*.test.js')
.pipe(babel({
presets: ['es2015'],
}))
.pipe(mocha({
reporter: 'Spec',
}))
);
gulp.task('lint', () =>
gulp.src(['./app/**/*.js', '!node_modules/**'])
.pipe(eslint())
.pipe(eslint.formatEach())
.pipe(eslint.failAfterError())
);
gulp.task('generate-service-worker', ['bundle', 'css', 'html', 'image', 'fonts'], (cb) => {
writeServiceWorker(rootDir, (env === 'production'), cb);
});
gulp.task('default', (cb) => {
runSequence('generate-service-worker', 'watch', () => {
nodemon({
script: './server.js',
ignore: ['./public/'],
});
cb();
});
});