-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
116 lines (98 loc) · 3.04 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
const gulp = require('gulp'),
clean = require('gulp-clean')
const browserify = require('browserify'),
babelify = require('babelify')
const source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
merge = require('gulp-merge')
const uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
sourcemaps = require('gulp-sourcemaps')
const sass = require('gulp-sass'),
csso = require('gulp-csso'),
gcmq = require('gulp-group-css-media-queries')
prefix = require('gulp-autoprefixer')
const mainBowerFiles = require('main-bower-files'),
browserSync = require('browser-sync'),
gulpSequence = require('gulp-sequence')
const SRC = './ui/src',
VIEWS = './ui/views'
PRODUCTION = './ui/production'
const BROWSERS = [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
]
gulp.task('bower-css', () => {
return gulp.src(mainBowerFiles('**/*.css'))
.pipe(concat('bundle.css'))
.pipe(gulp.dest(`${PRODUCTION}/css`))
})
gulp.task('bower-js', () => {
return gulp.src(mainBowerFiles('**/*.js'))
.pipe(concat('bundle.js'))
.pipe(uglify())
.pipe(gulp.dest(`${PRODUCTION}/js`))
})
gulp.task('sass', () => {
return gulp.src(`${SRC}/scss/app.scss`)
.pipe(sass())
.pipe(prefix(BROWSERS))
.pipe(gcmq())
.pipe(csso())
.pipe(gulp.dest(`${PRODUCTION}/css`))
})
gulp.task('js', () => {
var bundler = browserify({
entries: [`${SRC}/js/app.js`],
debug: true
})
var bundle = () => {
return bundler
.transform('babelify', {presets: ['es2015']})
.bundle()
.pipe(source('app.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(`${PRODUCTION}/js`))
}
return bundle()
})
gulp.task('sync', () => {
browserSync.init(null, {
proxy: "http://localhost:3011",
port: 7000,
open: false,
browser: "chrome",
files: [`${PRODUCTION}/**/*.*`, `${VIEWS}/**/*.pug`],
reloadDelay: 2000
})
})
gulp.task('watch', () => {
gulp.watch(`${SRC}/scss/**/*.scss`, {cwd:'./'}, ['sass'])
gulp.watch(`${SRC}/js/**/*.js`, {cwd:'./'}, ['js'])
gulp.watch(`${SRC}/assets/**/*.*`, {cwd:'./'}, ['copy-assets'])
})
gulp.task('copy-assets', () => {
return gulp.src(`${SRC}/assets/**/*.*`)
.pipe(gulp.dest(`${PRODUCTION}/assets`))
})
gulp.task('copy-static', () => {
return gulp.src(`${SRC}/static/**/*.*`)
.pipe(gulp.dest(`${PRODUCTION}/static`))
})
gulp.task('clean', () => {
return gulp.src(PRODUCTION, { read: false })
.pipe(clean())
})
gulp.task('bower', ['bower-css', 'bower-js'])
gulp.task('build', gulpSequence('clean', 'sass', 'js', 'copy-assets', 'copy-static', 'bower'))
gulp.task('default', gulpSequence('build', 'watch', 'sync'))