2018-03-27 05:44:14 +00:00
|
|
|
const babel = require('gulp-babel');
|
|
|
|
const concat = require('gulp-concat');
|
|
|
|
const cssmin = require('gulp-cssmin');
|
|
|
|
const del = require('del');
|
|
|
|
const gulp = require('gulp');
|
|
|
|
const gulpif = require('gulp-if');
|
|
|
|
const postcss = require('gulp-postcss');
|
|
|
|
const rev = require('gulp-rev');
|
2018-03-31 05:05:33 +00:00
|
|
|
const uglify = require('gulp-uglify-es').default;
|
2018-03-31 04:58:38 +00:00
|
|
|
const webpackStream = require('webpack-stream');
|
|
|
|
const webpackConfig = require('./webpack.config.js');
|
2018-05-28 21:16:03 +00:00
|
|
|
const sourcemaps = require('gulp-sourcemaps');
|
2018-05-31 15:59:18 +00:00
|
|
|
const through = require('through2');
|
2018-03-27 05:44:14 +00:00
|
|
|
|
|
|
|
const argv = require('yargs')
|
|
|
|
.default('production', false)
|
|
|
|
.argv;
|
|
|
|
|
|
|
|
const paths = {
|
|
|
|
manifest: './public/assets',
|
2018-05-28 21:16:03 +00:00
|
|
|
assets: './public/assets/{css,scripts}/*.{css,css.map,js,js.map}',
|
2018-03-27 05:44:14 +00:00
|
|
|
styles: {
|
2018-05-26 19:33:27 +00:00
|
|
|
src: './resources/assets/styles/main.css',
|
2018-03-27 05:44:14 +00:00
|
|
|
dest: './public/assets/css',
|
|
|
|
},
|
|
|
|
scripts: {
|
2018-05-26 19:33:27 +00:00
|
|
|
src: './resources/assets/scripts/**/*.{js,vue}',
|
|
|
|
watch: ['./resources/assets/scripts/**/*.{js,vue}', './resources/lang/locales.js'],
|
2018-03-27 05:44:14 +00:00
|
|
|
dest: './public/assets/scripts',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-05-31 15:59:18 +00:00
|
|
|
const clearSourcemaps = through.obj(function (file, enc, cb) {
|
|
|
|
if (!/\.map$/.test(file.path)) this.push(file);
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
|
2018-03-27 05:44:14 +00:00
|
|
|
/**
|
|
|
|
* Build un-compiled CSS into a minified version.
|
|
|
|
*/
|
|
|
|
function styles() {
|
|
|
|
return gulp.src(paths.styles.src)
|
2018-05-28 21:16:03 +00:00
|
|
|
.pipe(sourcemaps.init())
|
2018-03-27 05:44:14 +00:00
|
|
|
.pipe(postcss([
|
|
|
|
require('postcss-import'),
|
2018-03-31 20:51:18 +00:00
|
|
|
require('tailwindcss')('./tailwind.js'),
|
2018-05-27 22:37:03 +00:00
|
|
|
require('precss'),
|
2018-03-31 04:58:38 +00:00
|
|
|
require('postcss-preset-env')({stage: 0}),
|
|
|
|
require('autoprefixer'),
|
|
|
|
]))
|
2018-03-27 05:44:14 +00:00
|
|
|
.pipe(gulpif(argv.production, cssmin()))
|
|
|
|
.pipe(concat('bundle.css'))
|
|
|
|
.pipe(rev())
|
2018-05-28 21:16:03 +00:00
|
|
|
.pipe(sourcemaps.write('.'))
|
2018-03-27 05:44:14 +00:00
|
|
|
.pipe(gulp.dest(paths.styles.dest))
|
2018-03-31 04:58:38 +00:00
|
|
|
.pipe(rev.manifest(paths.manifest + '/manifest.json', {merge: true, base: paths.manifest}))
|
2018-03-27 05:44:14 +00:00
|
|
|
.pipe(gulp.dest(paths.manifest));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build all of the waiting scripts.
|
|
|
|
*/
|
|
|
|
function scripts() {
|
2018-03-31 04:58:38 +00:00
|
|
|
return webpackStream(webpackConfig)
|
2018-05-31 15:59:18 +00:00
|
|
|
.pipe(sourcemaps.init({loadMaps: true}))
|
|
|
|
.pipe(clearSourcemaps)
|
2018-03-27 05:44:14 +00:00
|
|
|
.pipe(babel())
|
|
|
|
.pipe(gulpif(argv.production, uglify()))
|
|
|
|
.pipe(concat('bundle.js'))
|
|
|
|
.pipe(rev())
|
2018-05-28 21:16:03 +00:00
|
|
|
.pipe(sourcemaps.write('.'))
|
2018-03-27 05:44:14 +00:00
|
|
|
.pipe(gulp.dest(paths.scripts.dest))
|
2018-03-31 04:58:38 +00:00
|
|
|
.pipe(rev.manifest(paths.manifest + '/manifest.json', {merge: true, base: paths.manifest}))
|
2018-03-27 05:44:14 +00:00
|
|
|
.pipe(gulp.dest(paths.manifest));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-03-31 04:58:38 +00:00
|
|
|
* Provides watchers.
|
2018-03-27 05:44:14 +00:00
|
|
|
*/
|
|
|
|
function watch() {
|
2018-05-26 19:33:27 +00:00
|
|
|
gulp.watch(['./resources/assets/styles/**/*.css'], gulp.series(function cleanStyles() {
|
2018-03-31 04:58:38 +00:00
|
|
|
return del(['./public/assets/css/**/*.css']);
|
|
|
|
}, styles));
|
|
|
|
|
2018-04-08 20:18:13 +00:00
|
|
|
gulp.watch(paths.scripts.watch, gulp.series(function cleanScripts() {
|
2018-03-31 04:58:38 +00:00
|
|
|
return del(['./public/assets/scripts/**/*.js']);
|
|
|
|
}, scripts));
|
2018-03-27 05:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleanup unused versions of hashed assets.
|
|
|
|
*/
|
|
|
|
function clean() {
|
|
|
|
return del([paths.assets]);
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.clean = clean;
|
|
|
|
exports.styles = styles;
|
|
|
|
exports.scripts = scripts;
|
|
|
|
exports.watch = watch;
|
|
|
|
|
2018-03-31 04:58:38 +00:00
|
|
|
gulp.task('scripts', gulp.series(clean, scripts));
|
2018-03-27 05:44:14 +00:00
|
|
|
gulp.task('default', gulp.series(clean, styles, scripts));
|