Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build library and tweak #825

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,141 changes: 3,696 additions & 1,445 deletions build/css/custom.css

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions build/css/custom.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/css/maps/custom.min.css.map

Large diffs are not rendered by default.

9,790 changes: 4,887 additions & 4,903 deletions build/js/custom.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions build/js/custom.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/js/maps/custom.min.js.map

Large diffs are not rendered by default.

140 changes: 87 additions & 53 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,94 @@
var gulp = require('gulp'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
browserSync = require('browser-sync').create();
const { src, series, parallel, watch, dest } = require('gulp'),
autoprefixer = require('gulp-autoprefixer'),
cleanCSS = require('gulp-clean-css'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
plumber = require('gulp-plumber'),
rename = require('gulp-rename'),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify'),
browserSync = require('browser-sync').create()

var DEST = 'build/';
const DEST = 'build/'

gulp.task('scripts', function() {
return gulp.src([
'src/js/helpers/*.js',
'src/js/*.js',
])
.pipe(concat('custom.js'))
.pipe(gulp.dest(DEST+'/js'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest(DEST+'/js'))
.pipe(browserSync.stream());
});
const buildJs = done => {
src(['src/js/helpers/*.js', 'src/js/*.js'], { sourcemaps: true })
.pipe(
plumber({
errorHandler: notify.onError('<%= error.message %>')
})
)
.pipe(concat('custom.js'))
.pipe(dest(DEST + '/js'))
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(dest(DEST + '/js', { sourcemaps: './maps' }))
.pipe(browserSync.stream())
done()
}
buildJs.displayName = 'Build JS'

// TODO: Maybe we can simplify how sass compile the minify and unminify version
var compileSASS = function (filename, options) {
return sass('src/scss/*.scss', options)
.pipe(autoprefixer('last 2 versions', '> 5%'))
.pipe(concat(filename))
.pipe(gulp.dest(DEST+'/css'))
.pipe(browserSync.stream());
};
const buildCss = done => {
src('src/scss/*.scss', { sourcemaps: true })
.pipe(sourcemaps.init())
.pipe(
plumber({
errorHandler: notify.onError('<%= error.message %>')
})
)
.pipe(
sass({
outputStyle: 'expanded'
})
)
.pipe(concat('custom.css'))
.pipe(
autoprefixer({
browsers: ['last 2 versions']
})
)
.pipe(dest(DEST + '/css'))
.pipe(cleanCSS())
.pipe(
rename({
suffix: '.min'
})
)
.pipe(sourcemaps.write('./maps'))
.pipe(dest(DEST + '/css'))
.pipe(browserSync.stream())
done()
}
buildCss.displayName = 'Build CSS'

gulp.task('sass', function() {
return compileSASS('custom.css', {});
});
const startBrowserSync = done => {
browserSync.init({
port: 8080,
server: {
baseDir: './'
},
startPath: './production/index.html',
reloadOnRestart: true
})
done()
}
startBrowserSync.displayName = 'Start Browser Sync'

gulp.task('sass-minify', function() {
return compileSASS('custom.min.css', {style: 'compressed'});
});

gulp.task('browser-sync', function() {
browserSync.init({
server: {
baseDir: './'
},
startPath: './production/index.html'
});
});

gulp.task('watch', function() {
// Watch .html files
gulp.watch('production/*.html', browserSync.reload);
// Watch .js files
gulp.watch('src/js/*.js', ['scripts']);
// Watch .scss files
gulp.watch('src/scss/*.scss', ['sass', 'sass-minify']);
});
const watchAll = done => {
const browserReload = () => {
browserSync.reload()
done()
}
watch('src/scss/*.scss').on('change', series(buildCss, browserReload))
watch('src/js/*.js').on('change', series(buildJs, browserReload))
watch('production/*.html').on('change', series(browserReload))
}
watchAll.displayName = 'Watch All'

// Default Task
gulp.task('default', ['browser-sync', 'watch']);
exports.default = series(
parallel(buildJs, buildCss),
startBrowserSync,
watchAll
)
Loading