-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
70 lines (58 loc) · 1.65 KB
/
gulpfile.js
File metadata and controls
70 lines (58 loc) · 1.65 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
const gulp = require('gulp');
const uglify = require('gulp-uglify');
const minifyCss = require('gulp-clean-css');
const babel = require('gulp-babel');
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
gulp.task('lint-js', (done) => {
try {
execSync('npx eslint source/*.js', { stdio: 'inherit' });
done();
} catch (error) {
done(error);
}
});
gulp.task('lint-css', (done) => {
try {
execSync('npx stylelint source/*.css', { stdio: 'inherit' });
done();
} catch (error) {
done(error);
}
});
gulp.task('build-js', () => {
return gulp.src('source/index.js')
.pipe(babel({
presets: ["@babel/preset-env"]
}))
.pipe(uglify())
.pipe(gulp.dest('./'));
});
gulp.task('build-css', () => {
return gulp.src('source/style.css')
.pipe(minifyCss())
.pipe(gulp.dest('./'));
});
gulp.task('inline-html', (done) => {
let html = fs.readFileSync('source/index.html', 'utf8');
const css = fs.readFileSync('style.css', 'utf8');
const js = fs.readFileSync('index.js', 'utf8');
// Replace external CSS link with inline style tag
html = html.replace(
/<link rel="stylesheet" href="style\.css">/,
`<style>${css}</style>`
);
// Replace external JS script with inline script tag
html = html.replace(
/<script src="index\.js"><\/script>/,
`<script>${js}</script>`
);
fs.writeFileSync('index.html', html);
done();
});
gulp.task('build', gulp.series('lint-js', 'lint-css', 'build-js', 'build-css', 'inline-html'));
gulp.task('watch', () => {
gulp.watch('source/*', gulp.series('build'));
});
gulp.task('default', gulp.series('build'));