-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
executable file
·120 lines (106 loc) · 3.45 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
117
118
119
120
const gulp = require('gulp'),
babel = require('gulp-babel'),
watch = require('gulp-watch'),
uglify = require('gulp-uglify'),
sourcemaps = require('gulp-sourcemaps'),
buffer = require('vinyl-buffer'),
source = require('vinyl-source-stream'),
rename = require('gulp-rename'),
fs = require('fs'),
terser = require('gulp-terser'),
browserify = require('browserify'),
babelify = require('babelify'),
path = require('path'),
concat = require('gulp-concat'),
concatCss = require('gulp-concat-css'),
clean = require('gulp-clean'),
sourceMaps = require('gulp-sourcemaps');
var config = {
js: {
src: './src/js/**/*.js', // Entry point
srcPkg: './src/js/main.js', // Entry point
outputDir: './dist/', // Directory to save bundle to
outputDirPkg: './pkg',
outputFile: 'i18nInput.js' // Name to use for bundle
},
flags : {
src: ['src/flags/**/*.svg'],
dst: './dist/flags/',
dstPkg: './pkg/flags/'
},
css : {
outputDir: './dist/', // Directory to save bundle to
outputDirPkg: './pkg/', // Directory to save bundle to
}
};
gulp.task('css', function () {
return gulp.src('src/css/**/*.css')
.pipe(concatCss("style.css"))
.pipe(gulp.dest(config.css.outputDir));
});
gulp.task('cssPkg', function (done) {
return gulp.src('src/css/**/*.css')
.pipe(concatCss("style.css"))
.pipe(gulp.dest(config.css.outputDirPkg));
});
gulp.task('copy', function () {
return gulp.src(config.flags.src)
.pipe(gulp.dest(config.flags.dst));
});
gulp.task('copyPkg', function () {
return gulp.src(config.flags.src)
.pipe(gulp.dest(config.flags.dstPkg));
});
gulp.task('mergejs', function () {
return gulp.src(config.js.src)
.pipe(babel({
presets: ['@babel/preset-env'],
plugins: [
'@babel/plugin-transform-runtime',
'@babel/plugin-proposal-class-properties',
],
}))
.pipe(gulp.dest(config.js.outputDir))
});
gulp.task('packjs', function () {
return browserify({
entries: [config.js.srcPkg]
}).transform(babelify.configure({
presets: [[
'@babel/preset-env',
{
"useBuiltIns": 'usage',
"corejs": {"version": 3, "proposals": true},
"debug": false,
"targets": {
"esmodules": false,
"browsers": [
"> 0.25%, not dead"
]
}
}
]],
plugins: [
'@babel/plugin-transform-runtime',
'@babel/plugin-proposal-class-properties',
],
}))
.bundle()
.pipe(source(config.js.srcPkg))
.pipe(buffer())
.pipe(rename(config.js.outputFile))
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(terser())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.js.outputDirPkg))
});
gulp.task('clean', function() {
return gulp.src('dist/', {read: false, allowEmpty: true })
.pipe(clean());
});
gulp.task('cleanPkg', function() {
return gulp.src('pkg/', {read: false, allowEmpty: true})
.pipe(clean());
});
gulp.task('default', gulp.series('clean', gulp.parallel('mergejs', 'css', 'copy')));
gulp.task('pkg', gulp.series('cleanPkg', 'packjs', 'cssPkg', 'copyPkg'));