I freaking love working with technologies like Gulp, and wanted to share how to get my current Craft front-end workflow set up. With a few tweaks, this can also be used with virtually any other sites (I've used it with Laravel, static sites, ExpressionEngine, etc).
- project root/
- craft/
- templates/
- (your craft template files)
- templates/
- public/ (web root)
- assets/
- styles/
- js/
- images/
- assets/
- source/
- js/
- combined/ (these files will be collectively combined and minified and placed in the
public/assets/js/
folder asscripts.js
andscripts.min.js
) libs/ (useful for things like jquery) * (various .js files) plugins/ (useful for things that depend on libs, like plugins) * (various .js files) site.js (this is where your hand-coded js will go) - individual/ (these files will be individually minified and combined and placed in the
public/assets/js/
folder)- (various .js files)
- combined/ (these files will be collectively combined and minified and placed in the
- scss/ (these files will be processed and places in the
public/assets/styles
folder)- (various .scss files)
- styles.scss
- js/
- gulpfile.js (download and include)
- package.json
- gulp.png (optional)
- craft/
- If Node is not yet installed on the machine, it will need to be installed
- If a package.json file already exists with list of all of the dependencies that Gulp will need for the project, then you can simply switch to the project root directory in the site terminal and run the command
npm install
. This only needs to happen once so that the dependencies can be downloaded for the project. - If a package.json file does not exist, switch to the project root directory for the site in a terminal. For this configuration, you can install gulp and the needed dependencies using the command
npm install browser-sync gulp gulp-autoprefixer gulp-concat gulp-cssnano gulp-livereload gulp-newer gulp-notify gulp-plumber gulp-rename gulp-sass gulp-size gulp-sourcemaps gulp-uglify gulp-watch lazypipe node-sass --save-dev
. You only need to do this once so that the dependencies can be downloaded for the project.
Copy the gulp.js file (below) to the base of your site. The provided gulp.js file is set up to work with the following project directory structure.
- Change
'Your Site Name'
to the name of your site. - Change
yoursite.dev
to the domain name that browserSync will proxy.
If using Git, be sure to add the .gitignore rules to your site's .gitignore file
- To just compile the scripts and SCSS one time, simply run the command
gulp
. - To watch the templates, .scss, and .js files for changes, and to automatically compile and minify the relevant files, run the command
gulp serve-lr
. If the livereload browser extensions are installed and enabled, the browser will automatically refresh when any changes are made. - Additionally, you can run the command
gulp serve-bs
to run browser sync. It will also compile and minify the relevant files and reload the browser. Additionally, it will allow browsers to sync their scrolling and clicks. Also useful for testing the site on local network mobile devices.
Feel free to use an icon for the project notifications. Simply place a png image named gulp.png file in the project root, and the script will use it in the notifications. You can optionally download and include this generic gulp image.
Hi, thanks for this! One thing to note - in your directory structure guide above the scss directory should be inside the source directory in order for the gulp task to process the scss files