jellyfin-web/gulpfile.js

124 lines
3.7 KiB
JavaScript
Raw Normal View History

'use strict';
2020-02-27 11:11:35 -07:00
2020-02-28 01:01:22 -07:00
const { src, dest, series, parallel, watch } = require('gulp');
2020-02-27 14:03:11 -07:00
const browserSync = require('browser-sync').create();
2020-02-27 11:11:35 -07:00
const del = require('del');
const babel = require('gulp-babel');
2020-02-27 14:03:11 -07:00
const concat = require('gulp-concat');
2020-02-27 11:11:35 -07:00
const terser = require('gulp-terser');
const htmlmin = require('gulp-htmlmin');
const imagemin = require('gulp-imagemin');
2020-02-27 11:11:35 -07:00
const sourcemaps = require('gulp-sourcemaps');
2020-02-28 01:01:22 -07:00
const mode = require('gulp-mode')({
2020-03-16 10:12:05 -07:00
modes: ["development", "production"],
2020-02-28 01:01:22 -07:00
default: "development",
verbose: false
2020-03-09 14:55:47 -07:00
});
2020-03-16 07:30:14 -07:00
const stream = require('webpack-stream');
2020-02-27 14:03:11 -07:00
const inject = require('gulp-inject');
const postcss = require('gulp-postcss');
2020-02-28 01:49:01 -07:00
const sass = require('gulp-sass');
sass.compiler = require('node-sass')
2020-02-27 14:03:11 -07:00
2020-02-28 06:36:42 -07:00
2020-03-16 10:12:05 -07:00
if (mode.production()) {
2020-03-16 07:30:14 -07:00
var config = require('./webpack.prod.js');
2020-02-28 06:36:42 -07:00
} else {
2020-03-16 07:30:14 -07:00
var config = require('./webpack.dev.js');
2020-02-28 06:36:42 -07:00
}
2020-02-28 01:01:22 -07:00
function serve() {
2020-02-27 14:03:11 -07:00
browserSync.init({
server: {
baseDir: "./dist"
},
port: 8080
});
2020-02-28 01:01:22 -07:00
watch(['src/**/*.js', '!src/bundle.js'], javascript);
watch('src/bundle.js', webpack);
watch('src/**/*.css', css);
watch(['src/**/*.html', '!src/index.html'], html);
watch(['src/**/*.png', 'src/**/*.jpg', 'src/**/*.gif', 'src/**/*.svg'], images);
watch(['src/**/*.json', 'src/**/*.ico'], copy);
watch('src/index.html', injectBundle);
2020-03-16 07:30:14 -07:00
watch(['src/standalone.js', 'src/scripts/apploader.js'], standalone);
2020-02-27 14:03:11 -07:00
}
2020-03-16 07:30:14 -07:00
function standalone() {
return src(['src/standalone.js', 'src/scripts/apploader.js'], { base: './src/' })
2020-03-09 14:55:47 -07:00
.pipe(concat('scripts/apploader.js'))
.pipe(dest('dist/'));
2020-02-27 14:03:11 -07:00
}
2020-02-27 11:11:35 -07:00
function clean() {
return del(['dist/']);
2020-02-27 11:11:35 -07:00
}
function javascript() {
2020-03-16 07:30:14 -07:00
return src(['src/**/*.js', '!src/bundle.js'], { base: './src/' })
.pipe(mode.development(sourcemaps.init({ loadMaps: true })))
2020-03-09 14:55:47 -07:00
.pipe(babel({
presets: [
['@babel/preset-env']
]
}))
.pipe(terser({
keep_fnames: true,
mangle: false
}))
.pipe(mode.development(sourcemaps.write('.')))
.pipe(dest('dist/'))
.pipe(browserSync.stream());
2020-02-27 11:11:35 -07:00
}
2020-02-27 14:03:11 -07:00
function webpack() {
2020-03-16 07:30:14 -07:00
return stream(config)
2020-03-09 14:55:47 -07:00
.pipe(dest('dist/'))
.pipe(browserSync.stream());
2020-02-27 14:03:11 -07:00
}
2020-02-27 11:11:35 -07:00
function css() {
2020-03-16 07:30:14 -07:00
return src(['src/**/*.css', 'src/**/*.scss'], { base: './src/' })
.pipe(mode.development(sourcemaps.init({ loadMaps: true })))
2020-03-09 14:55:47 -07:00
.pipe(sass().on('error', sass.logError))
.pipe(postcss())
.pipe(mode.development(sourcemaps.write('.')))
.pipe(dest('dist/'))
.pipe(browserSync.stream());
2020-02-27 11:11:35 -07:00
}
function html() {
2020-03-16 07:30:14 -07:00
return src(['src/**/*.html', '!src/index.html'], { base: './src/' })
2020-03-16 10:12:05 -07:00
.pipe(mode.production(htmlmin({ collapseWhitespace: true })))
2020-03-09 14:55:47 -07:00
.pipe(dest('dist/'))
.pipe(browserSync.stream());
2020-02-27 11:11:35 -07:00
}
function images() {
2020-03-16 07:30:14 -07:00
return src(['src/**/*.png', 'src/**/*.jpg', 'src/**/*.gif', 'src/**/*.svg'], { base: './src/' })
2020-03-16 10:12:05 -07:00
.pipe(mode.production(imagemin()))
2020-03-09 14:55:47 -07:00
.pipe(dest('dist/'))
.pipe(browserSync.stream());
}
function copy() {
2020-03-16 07:30:14 -07:00
return src(['src/**/*.json', 'src/**/*.ico'], { base: './src/' })
2020-03-09 14:55:47 -07:00
.pipe(dest('dist/'))
.pipe(browserSync.stream());
}
2020-02-27 14:03:11 -07:00
function injectBundle() {
2020-03-16 07:30:14 -07:00
return src('src/index.html', { base: './src/' })
2020-03-09 14:55:47 -07:00
.pipe(inject(
2020-03-16 07:30:14 -07:00
src(['src/scripts/apploader.js'], { read: false }, { base: './src/' }), { relative: true }
2020-03-09 14:55:47 -07:00
))
.pipe(dest('dist/'))
.pipe(browserSync.stream());
2020-02-27 14:03:11 -07:00
}
exports.default = series(clean, parallel(javascript, webpack, css, html, images, copy), injectBundle)
2020-03-16 10:12:05 -07:00
exports.standalone = series(exports.default, standalone)
exports.serve = series(exports.standalone, serve)