forked from FrDH/mmenu-light
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
107 lines (93 loc) · 2.36 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
/*
Tasks:
$ gulp : Runs the "css" and "js" tasks.
$ gulp watch : Starts a watch on the "css" and "js" tasks.
*/
const { src, dest, watch, series, parallel } = require('gulp');
// For CSS
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const cleancss = require('gulp-clean-css');
// For JS
const typescript = require('gulp-typescript');
const webpack = require('webpack-stream');
// For polyfills
const concat = require('gulp-concat');
// Dirs
const inputDir = 'src';
const outputDir = 'dist';
const esmDir = 'esm';
/** CSS task */
const css = () => {
return src(inputDir + '/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer(['> 5%', 'last 5 versions']))
.pipe(cleancss())
.pipe(dest(outputDir));
};
/** JS transpile task */
const jsTtranspile = () => {
return src([
inputDir + '/**/*.d.ts', // Include all typings.
inputDir + '/**/*.ts' // Include the needed ts files.
])
.pipe(
typescript({
target: 'es5',
module: 'es6'
})
)
.pipe(dest(esmDir));
};
/** JS Pack task */
const jsPack = () => {
return src(inputDir + '/mmenu-light.js')
.pipe(
webpack({
// mode: 'development',
mode: 'production',
output: {
filename: 'mmenu-light.js'
}
// optimization: {
// minimize: false
// }
})
)
.pipe(dest(outputDir));
};
/*
$ gulp polyfills
*/
const polyfills = cb => {
// Some polyfills might rely on others,
// therefor we include 'em in a fixed order.
return src([
inputDir + '/polyfills/foreach.js',
inputDir + '/polyfills/matches.js',
inputDir + '/polyfills/closest.js',
inputDir + '/polyfills/after.js',
inputDir + '/polyfills/append.js',
inputDir + '/polyfills/event.js'
])
.pipe(concat('mmenu-light.polyfills.js'))
.pipe(dest(outputDir));
};
/*
$ gulp js
*/
const js = cb => {
series(jsTtranspile, jsPack)(cb);
};
/*
$ gulp
*/
exports.default = parallel(css, js, polyfills);
/*
$ gulp watch
*/
exports.watch = cb => {
watch(inputDir + '/**/*.scss', css);
watch(inputDir + '/**/*.ts', js);
cb();
};