-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
116 lines (99 loc) · 2.93 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');
const util = require('gulp-util');
const rename = require('gulp-rename');
const browserify = require('browserify');
const babelify = require('babelify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const uglify = require('gulp-uglify-es').default;
const eslint = require('gulp-eslint');
const sourcemaps = require('gulp-sourcemaps');
/* config
========================================================================== */
const appName = 'a11y-dropdown-component';
const eslintFileName = '.eslintrc.json';
const requireClassName = 'Dropdowns';
const demoAppName = 'main';
// paths
const paths = {
entry: 'src/',
output: 'dist/',
app: `${appName}.js`,
scripts: '**/*.js',
};
// demo paths
const demoPaths = {
entry: 'demo/src/',
output: 'demo/dist/',
app: `${demoAppName}.js`,
scripts: '**/*.js',
};
// environments
const production = !!util.env.env;
/* linter (eslint)
========================================================================== */
// task 'eslint'
gulp.task('eslint', () =>
gulp.src(`${paths.entry}${paths.scripts}`)
.pipe(eslint({
configFile: eslintFileName,
}))
.pipe(eslint.format())
);
/* demo
========================================================================== */
// task 'demo'
gulp.task('demo', ['eslint'], () => {
browserify({
entries: `${demoPaths.entry}${demoPaths.app}`,
debug: true,
})
.transform(babelify)
.bundle()
.on('error', err => {
console.error(`${err.message}${err.codeFrame}`);
})
.pipe(source(`${demoAppName}.js`))
.pipe(buffer())
.pipe(sourcemaps.init({
loadMaps: true,
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(demoPaths.output))
});
/* build (js, es)
========================================================================== */
// task 'js'
gulp.task('js', ['eslint'], () => {
browserify({
entries: `${paths.entry}${paths.app}`,
standalone: requireClassName,
})
.transform(babelify)
.bundle()
.on('error', err => {
console.error(`${err.message}${err.codeFrame}`);
})
.pipe(production ? source(`${appName}.min.js`) : source(`${appName}.js`))
.pipe(buffer())
.pipe(production ? uglify() : util.noop())
.pipe(gulp.dest(paths.output))
});
// task 'es'
gulp.task('es', () =>
gulp.src(`${paths.entry}${paths.scripts}`)
.pipe(rename(`${appName}.es.js`))
.pipe(production ? uglify() : util.noop())
.pipe(gulp.dest(paths.output))
);
// task 'build'
gulp.task('build', ['js', 'es']);
/* watch (js, es, demo)
========================================================================== */
gulp.task('watch', () => {
gulp.watch(`${paths.entry}${paths.scripts}`, ['js', 'es', 'demo']);
gulp.watch(`${demoPaths.entry}${demoPaths.scripts}`, ['demo']);
});
/* default (build)
========================================================================== */
gulp.task('default', ['build']);