jellyfin-web/gulpfile.js

126 lines
3.6 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')({
modes: ["production", "development"],
default: "development",
verbose: false
});
2020-02-27 14:03:11 -07:00
const webpack_stream = require('webpack-stream');
const inject = require('gulp-inject');
const postcss = require('gulp-postcss');
const cssnano = require('cssnano');
const autoprefixer = require('autoprefixer');
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
if(mode.production()) {
var webpack_config = require('./webpack.prod.js');
} else {
var webpack_config = require('./webpack.dev.js');
}
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-02-28 06:36:42 -07:00
watch(['src/standalone.js', 'src/scripts/apploader.js'], setStandalone);
2020-02-27 14:03:11 -07:00
}
function setStandalone() {
return src(['src/standalone.js', 'src/scripts/apploader.js'], {base: './src/'})
.pipe(concat('scripts/apploader.js'))
.pipe(dest('dist/'));
}
2020-02-27 11:11:35 -07:00
// Clean assets
function clean() {
return del(['dist/']);
2020-02-27 11:11:35 -07:00
}
function javascript() {
2020-02-27 14:03:11 -07:00
return src(['src/**/*.js', '!src/bundle.js'], {base: './src/'})
2020-02-28 01:01:22 -07:00
.pipe(mode.development(sourcemaps.init({loadMaps: true})))
2020-02-27 11:11:35 -07:00
.pipe(babel({
2020-02-28 06:36:42 -07:00
presets: [
['@babel/preset-env']
]
2020-02-27 11:11:35 -07:00
}))
.pipe(terser({
keep_fnames: true,
mangle: false
}))
2020-02-28 01:01:22 -07:00
.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() {
return webpack_stream(webpack_config)
2020-02-28 01:01:22 -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-02-28 01:49:01 -07:00
return src(['src/**/*.css', 'src/**/*.scss'], {base: './src/'})
2020-02-28 01:01:22 -07:00
.pipe(mode.development(sourcemaps.init({loadMaps: true})))
2020-02-28 01:49:01 -07:00
.pipe(sass().on('error', sass.logError))
2020-02-28 06:36:42 -07:00
.pipe(postcss())
2020-02-28 01:01:22 -07:00
.pipe(mode.development(sourcemaps.write('.')))
.pipe(dest('dist/'))
.pipe(browserSync.stream());
2020-02-27 11:11:35 -07:00
}
function html() {
2020-02-27 14:03:11 -07:00
return src(['src/**/*.html', '!src/index.html'], {base: './src/'})
2020-02-27 11:11:35 -07:00
.pipe(htmlmin({ collapseWhitespace: true }))
2020-02-28 01:01:22 -07:00
.pipe(dest('dist/'))
.pipe(browserSync.stream());
2020-02-27 11:11:35 -07:00
}
function images() {
return src(['src/**/*.png', 'src/**/*.jpg', 'src/**/*.gif', 'src/**/*.svg'], {base: './src/'})
.pipe(imagemin())
.pipe(dest('dist/'))
2020-02-28 01:01:22 -07:00
.pipe(browserSync.stream());
}
function copy() {
return src(['src/**/*.json', 'src/**/*.ico'], {base: './src/'})
.pipe(dest('dist/'))
2020-02-28 01:01:22 -07:00
.pipe(browserSync.stream());
}
2020-02-27 14:03:11 -07:00
function injectBundle() {
return src('src/index.html', {base: './src/'})
.pipe(inject(
src(['src/scripts/apploader.js'], {read: false}, {base: './src/'}), {relative: true}
))
.pipe(dest('dist/'))
2020-02-28 01:01:22 -07:00
.pipe(browserSync.stream());
2020-02-27 14:03:11 -07:00
}
exports.default = series(clean, parallel(javascript, webpack, css, html, images, copy), injectBundle)
2020-02-28 01:01:22 -07:00
exports.serve = series(exports.default, setStandalone, serve)