forked from GoogleChrome/chromium-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
executable file
·198 lines (182 loc) · 5.14 KB
/
gulpfile.babel.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
'use strict';
import gulp from 'gulp';
import babel from 'gulp-babel';
import dartSass from 'sass';
import gulpSass from 'gulp-sass';
const sass = gulpSass( dartSass );
import concat from 'gulp-concat';
import { deleteAsync } from 'del';
import uglifyEs from 'gulp-uglify-es';
const uglify = uglifyEs.default;
import rename from 'gulp-rename';
import license from 'gulp-license';
import eslint from 'gulp-eslint';
import eslintIfFixed from 'gulp-eslint-if-fixed';
import autoPrefixer from 'gulp-autoprefixer';
import { rollup } from 'rollup';
import rollupResolve from '@rollup/plugin-node-resolve';
import rollupBabel from '@rollup/plugin-babel';
import rollupMinify from 'rollup-plugin-babel-minify';
function uglifyJS() {
return uglify({
output: {comments: 'some'},
});
}
function addLicense() {
return license('Apache2', {
organization: 'Copyright (c) 2016 The Google Inc. All rights reserved.',
tiny: true
});
}
function rollupIgnoreUndefinedWarning(warning, warn) {
// There is currently a warning when using the es6 module from openapi.
// It is a common issue and can be suppresed.
// The error that is suppresed:
// The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
// https://github.com/rollup/rollup/issues/1518#issuecomment-321875784
// Suppres that error but continue to print the remaining errors.
if (warning.code === 'THIS_IS_UNDEFINED') return;
warn(warning); // this requires Rollup 0.46
}
gulp.task('lint', () => {
return gulp.src([
'client-src/js-src/*.js',
'client-src/elements/*.js',
'client-src/contexts/*.js',
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('lint-fix', () => {
return gulp.src([
'client-src/js-src/*.js',
'client-src/elements/*.js',
'client-src/contexts/*.js',
], {base: './'})
.pipe(eslint({fix:true}))
.pipe(eslint.format())
.pipe(eslintIfFixed('./'))
.pipe(eslint.failAfterError());
});
// Compile and automatically prefix stylesheets
// This task is deprecated. Use css directly.
gulp.task('styles', () => {
const AUTOPREFIXER_BROWSERS = [
'last 1 version',
'last 2 iOS versions'
];
// For best performance, don't add Sass partials to `gulp.src`
return gulp.src([
'client-src/sass/**/*.scss'
])
.pipe(sass({
precision: 10
}).on('error', sass.logError))
.pipe(autoPrefixer(AUTOPREFIXER_BROWSERS))
.pipe(gulp.dest('static/css'));
});
gulp.task('css', function() {
return gulp.src([
'node_modules/@shoelace-style/shoelace/dist/themes/light.css',
])
.pipe(concat('base.css'))
.pipe(gulp.dest('static/css'));
});
gulp.task('rollup', () => {
return rollup({
input: [
'client-src/components.js',
'client-src/js-src/openapi-client.js',
],
plugins: [
rollupResolve(),
rollupBabel({babelHelpers: 'bundled'}),
rollupMinify({mangle: false, comments: false}),
],
onwarn: rollupIgnoreUndefinedWarning,
}).then(bundle => {
return bundle.write({
dir: 'static/dist',
format: 'es',
sourcemap: true,
compact: true,
});
});
});
gulp.task('rollup-cjs', () => {
return rollup({
input: [
'client-src/js-src/openapi-client.js',
],
plugins: [
rollupResolve(),
rollupBabel({babelHelpers: 'bundled'}),
rollupMinify({mangle: false, comments: false}),
],
onwarn: rollupIgnoreUndefinedWarning,
}).then(bundle => {
return bundle.write({
dir: 'static/dist',
format: 'cjs',
sourcemap: true,
compact: true,
});
});
});
// Run scripts through babel.
gulp.task('js', () => {
return gulp.src([
'client-src/js-src/**/*.js',
// openapi-client has imports and needs to use rollup.
// exclude it from the list.
// Else, the file will need to be treated as a module.
// Browsers defer loading <script type="module"> tags and this client is
// needed early on page load.
'!client-src/js-src/**/openapi-client*.js',
])
.pipe(babel()) // Defaults are in .babelrc
.pipe(uglifyJS())
.pipe(addLicense()) // Add license to top.
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('static/js'));
});
// Clean generated files
gulp.task('clean', () => {
return deleteAsync([
// Disabled as part of removing sass/scss.
// 'static/css/',
'static/dist',
'static/js/',
], {dot: true});
});
// Build production files, the default task
gulp.task('default', gulp.series(
'clean',
// Incrementally removing sass/scss.
// 'styles',
'css',
'js',
'lint-fix',
'rollup',
'rollup-cjs',
));
// Build production files, the default task
gulp.task('watch', gulp.series(
'default',
function watch() {
gulp.watch(['client-src/sass/**/*.scss'], gulp.series('styles'));
gulp.watch([
'client-src/js-src/**/*.js',
'client-src/elements/*.js',
'client-src/elements/css/**/*.js',
'client-src/contexts/*.js',
], gulp.series(['lint', 'js']));
gulp.watch([
'client-src/components.js',
'client-src/elements/*.js',
'client-src/elements/css/**/*.js',
'client-src/contexts/*.js',
], gulp.series(['rollup']));
},
));