forked from jstable/JSTable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
97 lines (87 loc) · 2.85 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
const gulp = require('gulp');
const sass = require( 'gulp-sass' )(require('node-sass'));
const rename = require('gulp-rename');
const terser = require('gulp-terser');
const autoprefixer = require('gulp-autoprefixer');
const webpackStream = require('webpack-stream');
const TerserPlugin = require("terser-webpack-plugin");
function sassTask(cb) {
return gulp.src('src/jstable.scss')
.pipe(sass({ outputStyle: 'compressed' })
.on('error', printError))
.pipe(autoprefixer())
.pipe(gulp.dest('dist'));
}
function uglifyTask(cb) {
return gulp.src(['src/jstable.js'])
.pipe(terser())
.on('error', printError)
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('dist'))
}
function uglifyCompatibilityTask(cb) {
return gulp.src(['src/jstable.js'])
.pipe(webpackStream({
output: {
filename: 'jstable.js',
},
mode: 'production',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
}),
],
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: [
['@babel/preset-env', {
"useBuiltIns": "usage",
"corejs": 3
}]
]
}
}
}
]
}
}))
.pipe(rename({
suffix: '.es5.min'
}))
.pipe(gulp.dest('dist'))
}
function copyPolyfillFetch(cb) {
return gulp.src('node_modules/whatwg-fetch/dist/fetch.umd.js')
.pipe(terser())
.pipe(rename('polyfill-fetch.min.js'))
.pipe(gulp.dest('dist'))
}
function watchTask(cb) {
gulp.watch(['src/*.scss'], sassTask)
gulp.watch('src/*.js', gulp.series(uglifyTask, uglifyCompatibilityTask));
}
function printError(error) {
console.log('---- Error ----');
console.log("message", error.cause.message);
console.log("file", error.cause.filename);
console.log("line", error.cause.line);
console.log("col", error.cause.col);
console.log("pos", error.cause.pos);
console.log("");
// this will ensure that gulp will stop processing the pipeline without a crash
this.emit('end');
}
exports.sass = sassTask;
exports.uglify = gulp.series(uglifyTask, uglifyCompatibilityTask, copyPolyfillFetch);
exports.default = watchTask;