Getting Started
Getting started with the Better Boilerplate has a few prerequisites, mainly programs which are required to be installed for the Better Boilerplate to run and compile.
The Better Boilerplate assumes a working knowledge of HTML, CSS, SCSS/SASS, BEM (Block, Element, Modifier) and Javascript.
Prerequisites
In order to run the Better Boilerplate you will need to install some software first;
- NPM
- NPM (Node Package Manager) is required to be able to run gulp tasks and compile the SCSS. Install: https://www.npmjs.com/ .
- SASS/SCSS
- The Better Boilerplate is written in SCSS which is part of SASS (Syntactically Awesome Style Sheets) - SASS gives us access to features which are not readily available in vanilla CSS. Install: http://sass-lang.com/install .
- Gulp
- The Better Boilerplate makes use of Gulp as a task runner to help streamline some of the build process. Install: https://github.com/gulpjs/gulp/blob/master/docs/getting-started.md
Downloading
There are two variations of the Better Boilerplate;
- Plain Better Boilerplate
- The plain Better Boilerplate (CSS and Basic PHP files) is available for download from BitBucket .
- Betterpress
- The heavily modifed version of wordpress, complete with the Better Boilerplate is available for download from BitBucket . More documentation needs to be written around how to use and get up and running with BetterPress.
Installing
Once you have downloaded the Better Boilerplate and included it in your project files you will need to install the required npm modules, to do this; navigate to the root folder of you project and run the following command in terminal, the sudo command is to make sure you have admin rights to install the required node modules and will ask you to input your password;
$sudo npm install
You should also run;
$sudo npm update
Just to make sure the npm modules are up-to-date before getting started.
Gulp Tasks
The Better Boilerplate is making use of Gulp to automate much of the build process. You may wish to alter some of the settings in the gulpfile before beginning your project, such as the public or dist folder. To do this open the gulpfile.js found in the root folder of the Better Boilerplate and edit where necessary. The gulpfile is broken down into multiple tasks which can be run individually or all at once, all commands are run from the root folder of the Better Boilerplate in terminal:
- gulp
- Running the gulp command will run through all the tasks in the gulp file and will continually listen for changes in any of the source files and automatically compile them into the dist folder, this task can run in the background while you are working and will automatically recompile the code as you make changes.
All of the other gulp tasks will only run once and then stop. - gulp lint
- Running the gulp lint command will analyse JS files in the project for potential errors.
- gulp scripts
- Running the gulp scripts command will compile the JS files from src/js/vendor and main.js to dist/js into a single minified and concatenated file main.min.js.
- gulp other-scripts
- Running the gulp other-scripts command will copy any files inside the src/scripts/other-scripts folder to dist/js. These files will be minified and moved but their filename will remain the same.
- gulp styles
- Running the gulp styles command will compile all of the css found in the src/styles folder into a single CSS file main.css found in dist/css. The gulp styles during compilation will also auto-vendor-prefix many CSS3 elements, adding automatic support without the need for prefixes within your theme code.
- gulp styles-min
- Running the gulp styles-min command will do the same as the gulp styles command but will also rename and minify the compiled file (main.min.css) into dist/css.
- gulp clean
- Running the gulp clean command will remove the contents of the css and js folders inside dist.
- gulp images
- Running the gulp images command will copy and optimise all image inside the src/images folder into the dist/images folder. The compression settings used for the images can be adjusted inside the gulpfile.js
- gulp fonts
- Running the gulp fonts command will copy any custom fonts placed inside the src/fonts folder to the dist/fonts folder.
- gulp favicons
- Running the gulp favicons command will copy any custom favicons placed inside the src/favicons folder to the dist/favicons folder.
- gulp server
- The Better Boilerplate, by default, includes a task to run a local dev server on your machine. Running the gulp server command will boot up a local server on localhost:8080 which means you don't require a server to get started.
Betterpress does not include this gulp task. Additionally, you may want to remove this task if you are working within a framework such as Laravel or a CMS such as Craft or WordPress.
File Structure
The Better Boilerplate in broken down into multiple files and folders but follows a familiar and simple structure. Starting from the outside working in;
The top level is two folders /src and /dist. Using gulp tasks the Better Boilerplate will compile CSS and Javascript from the /src folder into the /dist folder.
Src
The /src folder is where you will edit all of your CSS, Javascript, fonts, favicons and images. The folder structure inside the src folder is simple and fairly self explanatory;
- Favicons
- Favicons should be placed in the /src/favicons folder.
- Fonts
- Any custom fonts should be placed in the /src/fonts folder.
- Images
- Images should be placed in the /src/images folder. Images placed into this folder are automatically optimised for the web and are, therefore, reduced in size. The compression settings used for the images can be adjusted from the gulpfile.js found in the root folder of the Better Boilerplate.
- PSDs
- The PSDs folder contains any editable assets which are required for external modules such as chosen select menus.
- Scripts
- The scripts folder contains a main.js file and two folders. The files contained in the /vendor folder and, also, the main.js file will be minified and then compiled into /dist/js/main.min.js. The second folder /other-scripts will be moved in the same folder in dist (/dist/js) but as a seperate file, this folder should be used for scripts which will not be needed on all pages.
- Styles
- The styles folder is broken down into 3 folders;
- better-boilerplate - This is the bulk of the CSS framework and SHOULD NOT BE EDITED DIRECTLY. Any code you wish to change should be overwritten using your own files in the theme folder.
- settings - The settings folder contains overrides and settings for pretty much everything included in the CSS Framework. The settings folder is covered in detail below.
- theme - The theme folder is where you should write your own CSS/SCSS. This folder is already broken down into multiple folders, containing files, most of which are empty, ready for you to start customising. If you need to add more theme files you can create them within the exisiting folder structure and then include them in the main.scss file found in the root of the styles folder.
- SVGs
- I am using a simple command-line tool to compile all SVG files into one SVG (svgs.svg). This tool can be downloaded and installed from https://github.com/jgarber623/svgeez . You can then use the following command from the root of your project to listen for changes to the folder. For more information on using SVGs please see the 'Using SVG' section below.
$svgeez watch --source src/svgs --destination dist/images/
Dist
The dist folder is automatically compiled using gulp tasks, CSS, Javascript, fonts, favicons and images SHOULD NOT BE EDITED from the /dist folder.
File Referencing
Files referenced inside CSS and Javascript should be done so using a relative file path, this is where gulp will compile the files;
src: url('../fonts/font-name.eot');
Where to Start
The best place to start with the Better Boilerplate is the settings folder and files, from there you can begin the setup based on the requirements of the project. This includes colours, optional modules, grid settings and more.
After the initial settings setup you can start writing you own theme code inside the src/styles/theme/ folder, including any overrides to the Better Boilerplate. You should NEVER EDIT any of the files inside the better-boilerplate folder.