-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
110 lines (101 loc) · 2.37 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
const gulp = require('gulp');
const postcss = require('gulp-postcss');
const postcss_plugins = {
nested: require('postcss-nested'),
};
const rename = require('gulp-rename');
const inline_source = require('gulp-inline-source-html');
const htmlmin = require('gulp-htmlmin');
const brotli = require('gulp-brotli');
const rollup = require('rollup');
const rollup_plugins = {
commonjs: require('@rollup/plugin-commonjs'),
nodeResolve: require('@rollup/plugin-node-resolve').default,
jsonResolve: require('@rollup/plugin-json'),
typescript: require('@rollup/plugin-typescript'),
terser: require('rollup-plugin-terser').default,
};
const { terser } = require('rollup-plugin-terser');
const replace = require('gulp-replace');
const {
readFileSync,
copyFileSync,
} = require('fs');
gulp.task('typescript', async () => {
const bundle = await rollup.rollup({
input: './src/js/index.ts',
plugins: [
rollup_plugins.commonjs(),
rollup_plugins.nodeResolve(),
rollup_plugins.jsonResolve(),
rollup_plugins.typescript({
tsconfig: './tsconfig.json',
outDir: './src/js',
}),
terser({
}),
],
});
return await bundle.write({
sourcemap: false,
format: 'es',
dir: './src/js/',
});
});
gulp.task('postcss', () => {
return gulp.src('./src/**/*.postcss').pipe(
postcss([
postcss_plugins.nested(),
])
).pipe(
rename({
extname: '.css'
})
).pipe(gulp.dest('./src/'));
});
gulp.task('build', () => {
const js = readFileSync('./src/js/index.js');
return gulp.src('./src/index.html').pipe(
inline_source()
).pipe(
replace(
'<script src="./js/index.js" async defer></script>',
`<script async defer>${js}</script>`
)
).pipe(
htmlmin({
collapseInlineTagWhitespace: false,
collapseWhitespace: true,
minifyCSS: true,
minifyJs: false,
removeAttributeQuotes: true,
preserveLineBreaks: false,
removeComments: true,
useShortDoctype: true,
})
).pipe(gulp.dest('./subtitle-editor/'));
});
gulp.task('compress', () => {
return gulp.src(
'./subtitle-editor/{index.html,schema.json}'
).pipe(
brotli.compress({
quality: 11,
})
).pipe(
gulp.dest('./subtitle-editor/')
);
});
gulp.task('copyschema', (cb) => {
copyFileSync('./src/schema.json', './subtitle-editor/schema.json');
return cb();
});
gulp.task('default', gulp.series(...[
gulp.parallel(...[
'typescript',
'postcss',
'copyschema',
]),
'build',
'compress',
]));