Gulp is an open-source automation toolkit for front-end development. It is built on Node.js and you can use it to automate repetitive and time-consuming tasks by setting up the gulpfile.js.
This post is going to illustrate how to set up the theme development environment for a Ghost theme. So basically we could have three folders under a root folder:
- the source folder
srccontains all theme development we are working in; - the destination folder
destis where we deploy and test the theme, usually its the theme folder of a local Ghost website; - the distribution folder
distis where we output the finished theme with a zip file.
The main tasks are:
- watch all file changes in the
./srcfolder and copy the exact same files to a./destfolder; - package the
./srcfiles into a zip file and put it in./distfolder.
Since gulp is based on Node.js and requires npm to install, you should have them installed in your computer.
Open your terminal tool and create a folder as the root folder:
Create a package.json file within the root folder with content {}.
Use npm to install gulp dependencies under root folder in dev mode:
After you install all the dev packages, your package.json file should look like:
Then we create a gulpfile.js file within the root folder with following content:
(in here I take the gulpfile I use for the Fizzy theme, you should change it based on your project.)
Here we create several tasks and at the end we use gulp.series to perform tasks sequentially.
Now you can run gulp dev to let gulp clean previous folder and then compile sass and watch file changes. After that, you can run gulp build to zip the files into a zip file under the dist folder.