forked from IdentityModel/oidc-client-js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
258 lines (237 loc) · 7.44 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
var gulp = require('gulp');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var webpackStream = require('webpack-stream');
var webpack = require('webpack');
var createWebpackConfig = require('./webpack.base');
var UglifyJsPlugin = require('uglifyjs-webpack-plugin');
// entry points for both configs
var npmEntry ='./index.js';
var classicEntry = ['babel-polyfill', npmEntry];
// npm compliant build with source-maps
function build_lib_sourcemap(){
// run webpack
return gulp.src('index.js').pipe(webpackStream(createWebpackConfig({
mode: 'development',
entry: npmEntry,
output: {
filename:'oidc-client.js',
libraryTarget:'umd',
// Workaround for https://github.com/webpack/webpack/issues/6642
globalObject: 'this'
},
plugins: [],
devtool:'inline-source-map'
}), webpack))
.pipe(gulp.dest('lib/'));
}
// npm compliant build without source-maps & minified
function build_lib_min(){
// run webpack
return gulp.src('index.js').pipe(webpackStream(createWebpackConfig({
mode: 'production',
entry: npmEntry,
output: {
filename:'oidc-client.min.js',
libraryTarget:'umd',
// Workaround for https://github.com/webpack/webpack/issues/6642
globalObject: 'this'
},
plugins: [],
devtool: false,
optimization: {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
keep_fnames: true
}
})
]
}
}), webpack))
.pipe(gulp.dest('lib/'));
}
// classic build with sourcemaps
function build_dist_sourcemap(){
// run webpack
return gulp.src('index.js').pipe(webpackStream(createWebpackConfig({
mode: 'development',
entry: classicEntry,
output: {
filename:'oidc-client.js',
libraryTarget:'var',
library:'Oidc'
},
plugins: [],
devtool:'inline-source-map'
}), webpack))
.pipe(gulp.dest('dist/'));
}
// classic build without sourcemaps & minified
function build_dist_min(){
// run webpack
return gulp.src('index.js').pipe(webpackStream(createWebpackConfig({
mode: 'production',
entry: classicEntry,
output: {
filename:'oidc-client.min.js',
libraryTarget:'var',
library:'Oidc'
},
plugins: [],
devtool: false,
optimization: {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
keep_fnames: true
}
})
]
}
}), webpack))
.pipe(gulp.dest('dist/'));
}
// this is used to manually build jsrsasign with the fewest modules to reduce its size
var files = [
'jsrsasign/header.js'
,'jsrsasign/ext/yahoo-min.js'
,'jsrsasign/ext/cj/cryptojs-312-core-fix-min.js'
,'jsrsasign/ext/cj/x64-core_min.js'
// ,'jsrsasign/ext/cj/cipher-core_min.js'
// ,'jsrsasign/ext/cj/aes_min.js'
// ,'jsrsasign/ext/cj/tripledes_min.js'
,'jsrsasign/ext/cj/enc-base64_min.js'
// ,'jsrsasign/ext/cj/md5_min.js'
// ,'jsrsasign/ext/cj/sha1_min.js'
,'jsrsasign/ext/cj/sha256_min.js'
// ,'jsrsasign/ext/cj/sha224_min.js'
,'jsrsasign/ext/cj/sha512_min.js'
,'jsrsasign/ext/cj/sha384_min.js'
// ,'jsrsasign/ext/cj/ripemd160_min.js'
// ,'jsrsasign/ext/cj/hmac_min.js'
// ,'jsrsasign/ext/cj/pbkdf2_min.js'
,'jsrsasign/ext/base64-min.js'
,'jsrsasign/ext/jsbn-min.js'
,'jsrsasign/ext/jsbn2-min.js'
,'jsrsasign/ext/prng4-min.js'
,'jsrsasign/ext/rng-min.js'
,'jsrsasign/ext/rsa-min.js'
// ,'jsrsasign/ext/rsa2-min.js'
,'jsrsasign/ext/ec-min.js'
,'jsrsasign/ext/ec-patch-min.js'
,'jsrsasign/ext/json-sans-eval-min.js'
,'jsrsasign/min/asn1-1.0.min.js'
,'jsrsasign/min/asn1hex-1.1.min.js'
// ,'jsrsasign/min/asn1x509-1.0.min.js'
// ,'jsrsasign/min/asn1cms-1.0.min.js'
// ,'jsrsasign/min/asn1tsp-1.0.min.js'
// ,'jsrsasign/min/asn1cades-1.0.min.js'
// ,'jsrsasign/min/asn1csr-1.0.min.js'
// ,'jsrsasign/min/asn1ocsp-1.0.min.js'
,'jsrsasign/min/base64x-1.1.min.js'
,'jsrsasign/min/crypto-1.1.min.js'
,'jsrsasign/min/ecdsa-modified-1.0.min.js'
,'jsrsasign/min/ecparam-1.0.min.js'
// ,'jsrsasign/min/dsa-2.0.min.js'
,'jsrsasign/min/keyutil-1.0.min.js'
,'jsrsasign/min/rsapem-1.1.min.js'
,'jsrsasign/min/rsasign-1.2.min.js'
,'jsrsasign/min/x509-1.1.min.js'
,'jsrsasign/min/jws-3.3.min.js'
// ,'jsrsasign/min/jwsjs-2.0.min.js'
,'jsrsasign/footer.js'
];
function build_jsrsasign(){
return gulp.src(files)
.pipe(concat('jsrsasign.js'))
.pipe(gulp.dest('jsrsasign/dist/'));
}
function copy_ts(){
return gulp.src('./index.d.ts')
.pipe(rename('oidc-client.d.ts'))
.pipe(gulp.dest('./dist/'));
}
// Replace the babel-polyfill with specific core-js polyfills.
function slimBuildTarget() {
return {
mode: 'production',
entry: ['./polyfills.js', './index.js'],
output: {
filename: 'oidc-client.slim.min.js',
libraryTarget: 'var',
library: 'Oidc'
},
plugins: [],
optimization: {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
compress: {
keep_fnames: true
}
}
})
]
}
};
}
function slimBuildTargetSourceMap() {
return {
mode: 'development',
entry: ['./polyfills.js', './index.js'],
output: {
filename: 'oidc-client.slim.js',
libraryTarget: 'var',
library: 'Oidc'
},
plugins: [],
devtool:'inline-source-map'
};
}
// Adds a configuration for slimming down the production build. This build
// does not contain the full babel-polyfill. Instead it imports specific
// core-js polyfills
function build_dist_slim() {
return gulp.src('index.js')
.pipe(webpackStream(createWebpackConfig(slimBuildTarget()), webpack))
.pipe(gulp.dest('dist/'));
};
function build_dist_slim_sourcemap() {
return gulp.src('index.js')
.pipe(webpackStream(createWebpackConfig(slimBuildTargetSourceMap()), webpack))
.pipe(gulp.dest('dist/'));
};
// Creates a build with only RSA256 exponent+modulus support (no X509)
function build_dist_slim_rsa() {
var conf = slimBuildTarget();
conf.output.filename = 'oidc-client.rsa256.slim.min.js';
// This plugin should always be first in the chain
conf.plugins.unshift(
new webpack.NormalModuleReplacementPlugin(/(.*)JoseUtil(\.js)?$/, (resource) => {
resource.request = resource.request.replace(/JoseUtil/, 'JoseUtilRsa');
})
);
return gulp.src('index.js')
.pipe(webpackStream(createWebpackConfig(conf), webpack))
.pipe(gulp.dest('dist/'));
};
function build_dist_slim_rsa_sourcemap() {
var conf = slimBuildTargetSourceMap();
conf.output.filename = 'oidc-client.rsa256.slim.js';
// This plugin should always be first in the chain
conf.plugins.unshift(
new webpack.NormalModuleReplacementPlugin(/(.*)JoseUtil(\.js)?$/, (resource) => {
resource.request = resource.request.replace(/JoseUtil/, 'JoseUtilRsa');
})
);
return gulp.src('index.js')
.pipe(webpackStream(createWebpackConfig(conf), webpack))
.pipe(gulp.dest('dist/'));
};
// putting it all together
exports.default = gulp.series(
build_jsrsasign,
gulp.parallel(build_lib_sourcemap, build_lib_min, build_dist_sourcemap, build_dist_min, build_dist_slim, build_dist_slim_rsa, build_dist_slim_sourcemap, build_dist_slim_rsa_sourcemap),
copy_ts
);