mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-17 02:48:19 -07:00
126 lines
3.6 KiB
JavaScript
126 lines
3.6 KiB
JavaScript
'use strict';
|
|
|
|
const { src, dest, series, parallel, watch } = require('gulp');
|
|
const browserSync = require('browser-sync').create();
|
|
const del = require('del');
|
|
const babel = require('gulp-babel');
|
|
const concat = require('gulp-concat');
|
|
const terser = require('gulp-terser');
|
|
const htmlmin = require('gulp-htmlmin');
|
|
const imagemin = require('gulp-imagemin');
|
|
const sourcemaps = require('gulp-sourcemaps');
|
|
const mode = require('gulp-mode')({
|
|
modes: ["production", "development"],
|
|
default: "development",
|
|
verbose: false
|
|
});
|
|
const webpack_stream = require('webpack-stream');
|
|
const inject = require('gulp-inject');
|
|
const postcss = require('gulp-postcss');
|
|
const cssnano = require('cssnano');
|
|
const autoprefixer = require('autoprefixer');
|
|
const sass = require('gulp-sass');
|
|
|
|
sass.compiler = require('node-sass')
|
|
|
|
|
|
if(mode.production()) {
|
|
var webpack_config = require('./webpack.prod.js');
|
|
} else {
|
|
var webpack_config = require('./webpack.dev.js');
|
|
}
|
|
|
|
function serve() {
|
|
browserSync.init({
|
|
server: {
|
|
baseDir: "./dist"
|
|
},
|
|
port: 8080
|
|
});
|
|
|
|
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);
|
|
watch(['src/standalone.js', 'src/scripts/apploader.js'], setStandalone);
|
|
}
|
|
|
|
function setStandalone() {
|
|
return src(['src/standalone.js', 'src/scripts/apploader.js'], {base: './src/'})
|
|
.pipe(concat('scripts/apploader.js'))
|
|
.pipe(dest('dist/'));
|
|
}
|
|
|
|
// Clean assets
|
|
function clean() {
|
|
return del(['dist/']);
|
|
}
|
|
|
|
function javascript() {
|
|
return src(['src/**/*.js', '!src/bundle.js'], {base: './src/'})
|
|
.pipe(mode.development(sourcemaps.init({loadMaps: true})))
|
|
.pipe(babel({
|
|
presets: [
|
|
['@babel/preset-env']
|
|
]
|
|
}))
|
|
.pipe(terser({
|
|
keep_fnames: true,
|
|
mangle: false
|
|
}))
|
|
.pipe(mode.development(sourcemaps.write('.')))
|
|
.pipe(dest('dist/'))
|
|
.pipe(browserSync.stream());;
|
|
}
|
|
|
|
function webpack() {
|
|
return webpack_stream(webpack_config)
|
|
.pipe(dest('dist/'))
|
|
.pipe(browserSync.stream());
|
|
}
|
|
|
|
function css() {
|
|
return src(['src/**/*.css', 'src/**/*.scss'], {base: './src/'})
|
|
.pipe(mode.development(sourcemaps.init({loadMaps: true})))
|
|
.pipe(sass().on('error', sass.logError))
|
|
.pipe(postcss())
|
|
.pipe(mode.development(sourcemaps.write('.')))
|
|
.pipe(dest('dist/'))
|
|
.pipe(browserSync.stream());
|
|
}
|
|
|
|
function html() {
|
|
return src(['src/**/*.html', '!src/index.html'], {base: './src/'})
|
|
.pipe(htmlmin({ collapseWhitespace: true }))
|
|
.pipe(dest('dist/'))
|
|
.pipe(browserSync.stream());
|
|
}
|
|
|
|
function images() {
|
|
return src(['src/**/*.png', 'src/**/*.jpg', 'src/**/*.gif', 'src/**/*.svg'], {base: './src/'})
|
|
.pipe(imagemin())
|
|
.pipe(dest('dist/'))
|
|
.pipe(browserSync.stream());
|
|
}
|
|
|
|
function copy() {
|
|
return src(['src/**/*.json', 'src/**/*.ico'], {base: './src/'})
|
|
.pipe(dest('dist/'))
|
|
.pipe(browserSync.stream());
|
|
}
|
|
|
|
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/'))
|
|
.pipe(browserSync.stream());
|
|
}
|
|
|
|
exports.default = series(clean, parallel(javascript, webpack, css, html, images, copy), injectBundle)
|
|
exports.serve = series(exports.default, setStandalone, serve)
|