-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
86 lines (78 loc) · 2.34 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
'use strict';
import {join, normalize} from 'path';
import gulp from 'gulp';
import sourceMaps from 'gulp-sourcemaps';
import autoprefixer from 'gulp-autoprefixer';
import babel from 'gulp-babel';
import concat from 'gulp-concat';
import uglify from 'gulp-uglify';
import sass from 'gulp-sass';
import browserify from 'gulp-browserify';
import babelify from 'babelify';
export const ROOT_DIR = normalize(join(__dirname));
export const CONFIG = {
JS: {
INPUT: [
'app.js'
],
OUTPUT: 'app.js'
},
DIR: {
SRC: 'src',
DIST: 'assets',
JS: 'javascript',
CSS: 'styles'
},
BROWSERS: [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
]
};
export function javascript(source = [], output = '') {
if (output == '' || source.length <= 0) return false;
return gulp.src(source)
.pipe(sourceMaps.init())
.pipe(browserify({
transform: ["babelify"],
entries: source.map(item => {
return join(ROOT_DIR, item);
}),
paths: [
join(ROOT_DIR, 'node_modules'),
join(ROOT_DIR, CONFIG.DIR.SRC)
]
}))
.pipe(babel({
presets: ['es2015']
}))
.pipe(concat(output))
.pipe(uglify())
.pipe(sourceMaps.write('.'))
.pipe(gulp.dest(`${CONFIG.DIR.DIST}/${CONFIG.DIR.JS}`));
};
export function styles() {
return gulp.src(`${CONFIG.DIR.SRC}/${CONFIG.DIR.CSS}/**/*.{sass,scss}`)
.pipe(
sass({
outputStyle: 'compressed'
}).on('error', sass.logError)
)
.pipe(autoprefixer(CONFIG.BROWSERS))
.pipe(gulp.dest(`${CONFIG.DIR.DIST}/${CONFIG.DIR.CSS}`));
};
gulp.task('javascript', () => javascript(CONFIG.JS.INPUT.map(item => {
return join(CONFIG.DIR.SRC, CONFIG.DIR.JS, item);
}), CONFIG.JS.OUTPUT));
gulp.task('styles', () => styles());
gulp.task('default', ['javascript', 'styles']);
gulp.task('watch', ['default', 'javascript', 'styles'], () => {
gulp.watch(`${CONFIG.DIR.SRC}/${CONFIG.DIR.JS}/**/*.js`, ['javascript']);
gulp.watch(`${CONFIG.DIR.SRC}/${CONFIG.DIR.CSS}/**/*.{sass,scss}`, ['styles']);
});