Formula for building JavaScript and compiling SASS assets with Gulp 4 and Jekyll. Uses the powerful Rollup and BrowserSync as an added bonus.
You will need to add the following to your package.json
file:
"scripts": {
"preinstall": "bundle install --path vendor/bundle",
"start": "bundle exec gulp",
"build": "bundle exec gulp build",
"production": "bundle exec gulp --jekyllEnv='production'"
}
In your _config.yml
file make sure to add the following:
keep_files: [assets]
incremental: true
Last but not least, create a build.config.js
file in the root of your directory and add your build paths, eg:
export default {
jekyll: {
default: '_config.yml',
development: '_config_development.yml'
},
views: [
'./src/schema/**/*.yml',
'./src/views/collections/**/*.html',
'./src/views/includes/*.html',
'./src/views/layouts/*.html',
'./src/views/pages/*.md',
'./src/views/*.html',
],
scripts: {
src: './src/scripts/bundle.js',
dest: './dist/assets/bundle.min.js'
},
styles: {
src: 'src/styles/**/*.scss',
dest: 'dist/assets'
},
browserSync: {
open: false,
ghostMode: false,
server: {
baseDir: './dist'
}
}