-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
108 lines (96 loc) · 2.47 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
require("harmonize")();
var babelify = require('babelify');
var browserify = require('browserify');
var debug = require('gulp-debug');
var del = require('del');
var gulp = require('gulp');
var jest = require('gulp-jest');
var path = require('path');
var plumber = require('gulp-plumber');
var rename = require('gulp-rename');
var source = require('vinyl-source-stream');
var uglify = require('gulp-uglify');
var watch = require('gulp-watch');
var package = require('./package.json');
var scriptsPath = package.paths.scripts;
var buildPath = package.paths.build;
var examplePath = package.paths.example;
var testPath = package.paths.test;
var appName = package.name;
var appFile = 'app.js';
var appDistFile = appName + '.js';
var appMinDistFile = appName + '.min.js';
gulp.task('devloop', function() {
gulp.watch([scriptsPath + '/**/*.*'], ['dev']);
})
gulp.task('jest', function() {
return gulp.src('__tests__')
.pipe(jest({
"globals": {
"__DEV__": true
},
"scriptPreprocessor": "./preprocessor.js",
"testPathIgnorePatterns": [
"test_helper.js",
"preprocessor.js"
],
"testFileExtensions": [
"js",
"react",
"jsx"
],
"unmockedModulePathPatterns": [
"..//node_modules/react"
]
}));
});
gulp.task('testWatch', function() {
gulp.watch([scriptsPath + '/**/*.*', './__tests__/**/*.*'], ['jest']);
})
gulp.task('example', () => {
return browserify({
entries: './src/' + appFile,
extensions: ['.js'],
debug: true
})
.transform(babelify.configure({
presets: [
"@babel/preset-env",
"@babel/preset-react",
]
}))
.bundle()
.pipe(source(appDistFile))
.pipe(gulp.dest('example/public/js'))
});
gulp.task('delete', () =>
new Promise((resolve, reject) =>
del('dist/*.js', (err, deletedFiles) => {
console.log("Files deleted:",deletedFiles.join(', '));
resolve();
})
)
);
gulp.task('build', gulp.series('delete', () =>
browserify({
entries: './src/' + appFile,
extensions: ['.js'],
})
.transform(babelify.configure({
presets: [
"@babel/preset-env",
"@babel/preset-react",
]
}))
.bundle()
.pipe(source(appDistFile))
.pipe(gulp.dest('dist'))
));
gulp.task('compress', gulp.series('build', () =>
gulp.src('dist/' + appDistFile)
.pipe(uglify())
.pipe(rename(appMinDistFile))
.pipe(gulp.dest('dist'))
));
gulp.task('default', gulp.series('example'));
gulp.task('dist', gulp.series('compress'));