-
-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathgulpfile.mjs
More file actions
142 lines (138 loc) · 5.05 KB
/
Copy pathgulpfile.mjs
File metadata and controls
142 lines (138 loc) · 5.05 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import gulp from 'gulp';
import {deleteAsync} from 'del';
import gp_sourcemaps from 'gulp-sourcemaps';
import gp_concat from 'gulp-concat';
import gp_rename from 'gulp-rename';
import gp_filter from 'gulp-filter';
import gp_uglify from 'gulp-uglify';
import gp_wrap from 'gulp-wrap';
import webpack from 'webpack-stream';
const esBuildDir = 'es-build/';
// AMD wrapper template
const amdWrapper = `(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof module === 'object' && module.exports) {
// Node/CommonJS
module.exports = factory(require('jquery'));
} else {
// Browser globals
factory(root.jQuery);
}
}(typeof self !== 'undefined' ? self : this, function ($) {
<%= contents %>
// Make laravelValidation accessible via $.laravelValidation (in addition to global scope)
$.laravelValidation = laravelValidation;
return $;
}));
`;
gulp.task('build', gulp.series(
function () {
return gulp.src(['resources/assets/js/helpers.js'])
.pipe(webpack({
target: ['web', 'es5'],
devtool: 'inline-source-map',
mode: 'development',
output: {
filename: 'helpers.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
"plugins": [
['@babel/plugin-transform-runtime', {debug: true}]
]
}
}
}
]
}
}))
.pipe(gulp.dest(esBuildDir));
},
function () {
return gulp.src([
'node_modules/jquery-validation/dist/jquery.validate.js',
'node_modules/php-date-formatter/js/php-date-formatter.js',
'resources/assets/js/jsvalidation.js',
esBuildDir + '/helpers.js',
'resources/assets/js/timezones.js',
'resources/assets/js/validations.js'
], {base: '.'})
.pipe(gp_sourcemaps.init())
.pipe(gp_concat('jsvalidation.js'))
.pipe(gp_sourcemaps.write('./'))
.pipe(gulp.dest('public/js'))
// gp_sourcemaps will cause two files to be in the stream (common.js and common.js.map) which means
// gp_uglify will try to run on the .map file as well, resulting in an error. gulp-filter only
// passes .js files from this point (https://stackoverflow.com/a/39675819)
.pipe(gp_filter('**/*.js'))
.pipe(gp_rename({ extname: '.min.js' }))
.pipe(gp_uglify())
.pipe(gp_sourcemaps.write('./'))
.pipe(gulp.dest('public/js'));
},
function () {
return deleteAsync(esBuildDir);
}
));
// AMD-compatible build
gulp.task('build-amd', gulp.series(
function () {
return gulp.src(['resources/assets/js/helpers.js'])
.pipe(webpack({
target: ['web', 'es5'],
devtool: 'inline-source-map',
mode: 'development',
output: {
filename: 'helpers.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
"plugins": [
['@babel/plugin-transform-runtime', {debug: true}]
]
}
}
}
]
}
}))
.pipe(gulp.dest(esBuildDir));
},
function () {
return gulp.src([
'node_modules/jquery-validation/dist/jquery.validate.js',
'node_modules/php-date-formatter/js/php-date-formatter.js',
'resources/assets/js/jsvalidation.js',
esBuildDir + '/helpers.js',
'resources/assets/js/timezones.js',
'resources/assets/js/validations.js'
], {base: '.'})
.pipe(gp_sourcemaps.init())
.pipe(gp_concat('jsvalidation.amd.js'))
.pipe(gp_wrap(amdWrapper))
.pipe(gp_sourcemaps.write('./'))
.pipe(gulp.dest('public/js'))
.pipe(gp_filter('**/*.js'))
.pipe(gp_rename({ extname: '.min.js' }))
.pipe(gp_uglify())
.pipe(gp_sourcemaps.write('./'))
.pipe(gulp.dest('public/js'));
},
function () {
return deleteAsync(esBuildDir);
}
));