2022-01-11 19:56:55 +00:00
|
|
|
import { dest, series, parallel, src, watch as gwatch } from 'gulp'
|
|
|
|
import autoprefixer from 'autoprefixer'
|
|
|
|
import browserSync from 'browser-sync'
|
|
|
|
import spawn from 'cross-spawn'
|
|
|
|
import cssnano from 'cssnano'
|
|
|
|
import postcss from 'gulp-postcss'
|
|
|
|
import atimport from 'postcss-import'
|
|
|
|
import imagemin from 'gulp-imagemin'
|
|
|
|
import minify from 'gulp-minify'
|
|
|
|
import tailwindcss from 'tailwindcss'
|
|
|
|
|
|
|
|
const SITE_ROOT = './_site'
|
|
|
|
const POST_BUILD_STYLESHEET = `${SITE_ROOT}/assets/css/`
|
|
|
|
const PRE_BUILD_STYLESHEET = './assets/css/style.css'
|
|
|
|
const IMAGES = './assets/img/**/*'
|
|
|
|
const IMAGES_MINIMIZED = `${SITE_ROOT}/assets/img/`
|
|
|
|
const TAILWIND_CONFIG = './tailwind.config.js'
|
2021-12-14 04:03:25 +00:00
|
|
|
|
|
|
|
// Fix for Windows compatibility
|
2022-01-11 19:56:55 +00:00
|
|
|
const jekyll = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll'
|
2021-12-14 04:03:25 +00:00
|
|
|
|
2022-01-11 19:56:55 +00:00
|
|
|
const isDevelopmentBuild = process.env.NODE_ENV === 'development'
|
2021-12-14 04:03:25 +00:00
|
|
|
|
2022-01-11 19:56:55 +00:00
|
|
|
const content = () => {
|
|
|
|
browserSync.notify('Building Jekyll site...')
|
2021-12-14 04:03:25 +00:00
|
|
|
|
2022-01-11 19:56:55 +00:00
|
|
|
const args = ['exec', jekyll, 'build']
|
2021-12-14 04:03:25 +00:00
|
|
|
if (isDevelopmentBuild) {
|
2022-01-11 19:56:55 +00:00
|
|
|
args.push('--incremental')
|
2021-12-14 04:03:25 +00:00
|
|
|
}
|
|
|
|
|
2022-01-11 19:56:55 +00:00
|
|
|
return spawn('bundle', args, { stdio: 'inherit' })
|
|
|
|
}
|
2021-12-14 04:03:25 +00:00
|
|
|
|
2022-01-11 19:56:55 +00:00
|
|
|
const scripts = () =>
|
|
|
|
src('./assets/js/*')
|
|
|
|
.pipe(minify({ext:{min:'.min.js' }, mangle: true}))
|
|
|
|
.pipe(dest(`${SITE_ROOT}/assets/js/`))
|
|
|
|
.pipe(browserSync.stream())
|
2021-12-14 04:03:25 +00:00
|
|
|
|
2022-01-11 19:56:55 +00:00
|
|
|
const styles = () =>
|
|
|
|
src(PRE_BUILD_STYLESHEET)
|
2021-12-14 04:03:25 +00:00
|
|
|
.pipe(
|
2022-01-11 19:56:55 +00:00
|
|
|
postcss([
|
|
|
|
atimport(),
|
|
|
|
tailwindcss(TAILWIND_CONFIG),
|
|
|
|
...(isDevelopmentBuild ? [] : [autoprefixer(), cssnano()]),
|
|
|
|
])
|
|
|
|
)
|
|
|
|
.pipe(dest(POST_BUILD_STYLESHEET))
|
|
|
|
.pipe(browserSync.stream())
|
|
|
|
|
|
|
|
const cname = () =>
|
|
|
|
src('assets/CNAME').pipe(dest(SITE_ROOT))
|
|
|
|
|
|
|
|
const images = () =>
|
|
|
|
src(IMAGES)
|
|
|
|
.pipe(imagemin([
|
|
|
|
imagemin.gifsicle({ interlaced: true }),
|
|
|
|
imagemin.optipng({ optimizationLevel: 3 }),
|
|
|
|
imagemin.svgo(),
|
|
|
|
]))
|
|
|
|
.pipe(dest(IMAGES_MINIMIZED))
|
|
|
|
.pipe(browserSync.stream())
|
|
|
|
|
|
|
|
const server = () =>
|
2021-12-14 04:03:25 +00:00
|
|
|
browserSync.init({
|
2022-01-11 19:56:55 +00:00
|
|
|
files: [SITE_ROOT + '/**'],
|
|
|
|
open: 'local',
|
2021-12-14 04:03:25 +00:00
|
|
|
port: 4000,
|
|
|
|
server: {
|
|
|
|
baseDir: SITE_ROOT,
|
|
|
|
serveStaticOptions: {
|
2022-01-11 19:56:55 +00:00
|
|
|
extensions: ['html'],
|
2021-12-14 04:03:25 +00:00
|
|
|
},
|
|
|
|
},
|
2022-01-11 19:56:55 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const watch = () => {
|
|
|
|
gwatch(['_authors/*', '_data/*', '_posts/*', '_layouts/*', '_includes/*'], content)
|
|
|
|
gwatch('**/*.js', scripts)
|
|
|
|
gwatch(PRE_BUILD_STYLESHEET, styles)
|
|
|
|
gwatch(IMAGES, images)
|
|
|
|
//'!_site/**/*',
|
|
|
|
//'!node_modules/**/*',
|
|
|
|
}
|
|
|
|
|
|
|
|
const build = series(content, scripts, styles, images, cname)
|
|
|
|
|
|
|
|
exports.content = content
|
|
|
|
exports.scripts = scripts
|
|
|
|
exports.styles = styles
|
|
|
|
exports.images = images
|
|
|
|
exports.cname = cname
|
|
|
|
exports.watch = watch
|
|
|
|
exports.server = server
|
|
|
|
exports.build = build
|
|
|
|
exports.devel = series(build, parallel(server, watch))
|
|
|
|
exports.default = exports.build
|