-
Notifications
You must be signed in to change notification settings - Fork 17
/
gulpfile.babel.js
144 lines (129 loc) · 3.36 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
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
import gulp from 'gulp';
import {spawnSync} from 'child_process';
import del from 'del';
import stylelint from 'gulp-stylelint';
import eslint from 'gulp-eslint';
import babel from 'gulp-babel';
import webpackStream from 'webpack-stream';
import webpackConfig from './webpack.config';
import exampleWebpackConfig from './example/webpack.config';
import webpack from 'webpack';
import sass from 'gulp-sass';
import filter from 'gulp-filter';
import postcss from 'gulp-postcss';
import autoprefixer from 'autoprefixer';
import cssnano from 'cssnano';
import concat from 'gulp-concat';
import pkg from './package.json';
import runSequence from 'run-sequence';
gulp.task('start', (callback) => {
let start = spawnSync('babel-node', ['example/webpack.server.js'], {stdio: 'inherit'});
if (start.stderr) {
callback(start.stderr);
}
});
gulp.task('build:lib:clean', () => {
del.sync(['lib', 'dist']);
});
gulp.task('build:lib:stylelint', () => {
return gulp
.src(['src/**/*.{css,scss,sass}'])
.pipe(stylelint({
failAfterError: true,
reporters: [
{formatter: 'string', console: true}
]
}));
});
gulp.task('build:lib:eslint', () => {
return gulp
.src(['src/**/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
gulp.task('build:lib:babel', () => {
return gulp
.src(['src/**/*.js'])
.pipe(babel())
.pipe(gulp.dest('lib'));
});
gulp.task('build:lib:umd', () => {
return gulp
.src(['src/index.js'])
.pipe(webpackStream(webpackConfig, webpack))
.pipe(gulp.dest('dist'));
});
gulp.task('build:lib:sass', () => {
let cssFilter = filter('**/*.css');
return gulp
.src(['src/**/*.scss', '!src/**/_*.scss'])
.pipe(sass({outputStyle: 'expanded'}).on('error', sass.logError))
.pipe(cssFilter)
.pipe(gulp.dest('lib'))
.pipe(concat(pkg.name + '.css'))
.pipe(postcss([
autoprefixer({
browsers: [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
]
}),
cssnano({
safe: true,
discardComments: {removeAll: true}
})
]))
.pipe(gulp.dest('dist'));
});
gulp.task('build:lib:copy', () => {
return gulp
.src(['src/**/*', '!src/**/*.{scss,js}'])
.pipe(gulp.dest('lib'))
.pipe(gulp.dest('dist'));
});
gulp.task('build:lib', (callback) => {
runSequence(
'build:lib:clean',
'build:lib:stylelint',
'build:lib:eslint',
'build:lib:babel',
'build:lib:umd',
'build:lib:sass',
'build:lib:copy',
callback
);
});
gulp.task('build:example:clean', () => {
del.sync(['example/dist']);
});
gulp.task('build:example:webpack', () => {
return gulp
.src(['example/app/app.js'])
.pipe(webpackStream(exampleWebpackConfig, webpack))
.pipe(gulp.dest('example/dist'));
});
gulp.task('build:example:copy', () => {
return gulp
.src(['example/app/*', '!example/app/*.{html,js}'], {nodir: true})
.pipe(gulp.dest('example/dist'));
});
gulp.task('build:example', (callback) => {
runSequence(
'build:example:clean',
'build:example:webpack',
'build:example:copy',
callback
);
});
gulp.task('build', (callback) => {
runSequence('build:lib', 'build:example', callback);
});
gulp.task('default', ['build']);