Op'ed front-end dev boilerplate with Sass and Jade on Gulp.
You can use Saja - Sassyjade's small and simple command line interface to start a new project. The CLI is installed via npm.
$ npm install -g saja
Once you have installed Saja - the Sassyjade CLI globally you can start a new project with 1 simple command:
$ saja <yourProject>
This command will fetch the latest version of Sassyjade boilerplate and install all its dependencies in a new folder called "yourProject", relative to the folder from where you ran the command.
Since the command also installs all necessary dependencies via npm you might run into some permission errors. In this case try to execute the command as super user: $ sudo saja <yourProject>
.
After that, to start working do:
$ cd <yourProject>
$ gulp watch
If you don't want the default folder and file structre of Sassyjade add the --blank
flag. You can also just use -b
instead.
$ saja --blank <yourProject>
If for some reason you don't want or cannot use Saja - the Sassyjade CLI you may alternatively just manually download the latest version of the Sassyjade boilerplate as a ZIP file.
To get started unzip the file into your project folder. Then check that in the root of your project folder the file package.json
exists. If it does go ahead and install Sassyjade's dependencies via npm and then start the gulp process.
$ sudo npm install
$ gulp watch
Sassyjade is a frontend development boilerplate and build process. It uses the template language Jade to build html pages, the Sass preprocessor to generate css stylesheets and Gulp to manage the build processes. Please refer to the documentation of these awesome tools to find out more what these do, how these work and why these are useful.
Sassyjade is opinionated. This means it has a default folder and file structure which dictate the workflow in a broad way.
However, the folder and file structure can be changed via the sassyjade.config.json
file to match your preferences.
app-root
|-sassyjade.config.json
|-node_modules/
|-src/
| |-assets/
| | |-files/
| | |-font/
| | |-img/
| | |-docs/
| |-scripts/
| |-styles/
| |-templ/
| | |-incl/
| | | |-config.jade
| | |-mixin/
| | | |-jadestones.jade
| | |-layout/
| | | |-base.jade
| |-index.jade
|-gulpfile.js
|-package.json
|-dist/
Do take note that if you decide to change the folder structure, you also need to update the sassyjade.config.json
accordingly. Your project should always have a src
and a dist
folder at the minimum.
Contains all dependencies and is managed by npm.
The "source" folder - this is where the development files live.
Contains all static assets split into 4 sub-folders: images, fonts, docs and files for any other file type. Sassyjade expects your docs to by written in markdown.
Contains all javascripts which will be compiled to a single script.
Contains all CSS preprocessor files such as SASS and Stylus, which will be compiled to a single CSS stylesheet.
Contains Jade templates which will be compiled into html views.
The "production" folder - it is managed by Sassyjade. Generally there is no need to manipulate it manually.
The sassyjade.config.json
lets you define the paths in the source folders which are observed by Gulp.
Every object in the sassyjade.config.json
represents a the configuration settings for a Gulp task. The name of the object is identical with the Gulp task which can be called by this name. As such, the names should not be changed.
For example to change the path where to look for your Sass edit the style.src
property.
"styles": {
"src": [
"src/styles/**/*.{scss,styl}"
],
"dest": "dist/css/"
}
The default configuration for each Gulp task is documented together with the respective Gulp task itself.
Please note that you should not change the first and second level of sassyjade.config.json
as the gulp tasks depend on these. In above example only the values of src
and dest
should be changed. The first level, in above example styles
refers to the respective gulp task.
For the src
you can generally define more than one folders to observe. dest
on the other hand can always only have 1 folder.
In sassyjade.config.json
you can also define some basic global options.
"option": {
"messages": true,
"pretty": true,
"maps": true,
"jsName": "main.js",
"cssName": "main.css",
"livereloadOn": true,
"preprocessor": "sass"
}
Option | Values | Default | Description |
---|---|---|---|
messages |
boolean | true |
Shows Sassyjade system messages when tasks ran successfully. |
pretty |
boolean | true |
Makes the compiled html, css and JS human-readable |
maps |
boolean | true |
Writes sourcemaps of CSS and JS files. |
jsName |
string | "main.js" |
The name of the concatenated javascript. |
cssName |
string | "main.css" |
The name of the concatenated and compiled CSS file. |
livereloadOn |
boolean | true |
Automatic refresh of the browser on save (needs external browser plugin to work!) |
preprocessor |
string | "sass" |
The preprocessor of choice as string. Besides Sass also Stylus is supported. |
Sassyjade comes with multiple pre-defined gulp tasks.
For each task, default source and destination folders are predefined. They can be changed in sassyjade.config.json
if needed.
Make an all new build of the project. This command runs all other defined tasks once together. As this is the default Gulp task you can just use the shorthand $ gulp
instead.
Same as build but cleans out the dist/ folder completely beforehand. This is useful to ensure that files which were deleted from the src/ but still exist at the dist/ from earlier builds are deleted.
Looks up the index file in the source, compiles and copies it to the distribution version.
Sassyjade expects an index.jade
file at the /src/templ/
folder. This will be resolved to an index.html
file at the root of the /dist/
folder.
Sees jade files and compiles them into html. This task also runs the index task automatically.
"templ": {
"src": [
"src/templ/**/*.jade",
"!src/templ/index.jade",
"!src/templ/incl/*.jade",
"!src/templ/mixin/*.jade",
"!src/templ/layout/*.jade"
],
"dest": "dist/views/"
}
Due to its special nature the index.jade
file should generally be excluded. It is handled by the special $ gulp index
task. Sassyjade always expects the index files at the root folders in both /src/
and /dist/
.
Sees markdown (.md) files and compiles them into html.
"markdown": {
"src": [
"readme.md",
"src/assets/docs/**/*.md"
],
"dest": "dist/docs/"
}
Sassyjade assumes that the main readme file lives at the root of the project folder. It is generally the only evaluated file which should live there.
Identifies stylesheets of the preprocessor selected and compiles these into 1 css file.
"styles": {
"src": [
"src/styles/**/*.{scss,styl}"
],
"dest": "dist/css/"
}
Please note that only the files of the preprocessor set in sassyjade.config.json
are evaluated, despite declaring multiple file types.
Sees javascript files, concatenates and compiles them into one script file.
"scripts": {
"src": [
"src/scripts/**/*.js"
],
"dest": "dist/js/"
}
Please note that the order of the sources matters! For example, if you intend to use a library such as jQuery make sure to specify its source path first. This way, the files of the sources declared thereafter can depend on it.
Copies fonts from the source to the destination specified.
"font": {
"src": [
"src/assets/font/**/*.{eot,svg,ttf,woff,woff2,otf}"
],
"dest": "dist/font/"
}
Copies images from the source to the destination specified.
"img": {
"src": [
"src/assets/img/**/*.{png,jpg,gif}"
],
"dest": "dist/img/"
}
Copies changed files from the source into the destination selected.
"files": {
"src": [
"src/assets/files/**/*"
],
"dest": "dist/files/"
}
Runs the 3 tasks font
, img
and files
together.
Every defined stand-alone Gulp task comes with a built-in watcher that runs the task everytime a relevant file changes. To run a task and keep watching the files simply prepend the task with watch-
.
$ gulp watch-<task>
For example: to watch for changes on the jade templates run: $ gulp watch-jade
.
A special, global watch task that keeps track of all changes and updates the relevant files.
Every defined stand-alone Gulp taks comes with a built-in killer that deletes the task's output in the dist/ folder completely. To run the killer on any task simply prepend it with kill-
. Killers are useful to clean the dist/ from any old files which might have been deleted at the src/ but still exist at the dist/.
$ gulp kill-<task>
For example: to kill (= delete) all static-assets run: $ gulp kill-static-assets
.
Is a special, global kill task that deletes the entire dist/ folder completely. This might be useful before building for production to make sure all old files are wiped before uploading the build to the server.
Sassyjade is livereload enabled by default. In order for the browser to refresh automatically you need the respective livereload plugin. Refer to the livereload documentation.
Sassyjade has a predefined Jade templates structure. You are free to change it as you wish. Please note that this documentation only deals with the usage of Jade and its building blocks in context of the Sassyjade boilerplate. Please refer to the Jade API to understand how the language works in detail.
templ/
|--incl/ // contains reusable snippets
|--layout/ // defines the layout structure of pages
|--mixin/ // contains all mixin
All Jade files are contained within the templ
folder and are organized in 3 sub-folders. The actual templates which are evaluated to html live at the root directory. You can organize these in folders as well.
In the templ/incl
folder lives the config.jade
file. If you are using Sassyjade's CLI "saja" to setup your project, it allows you to configure this file via command line.
//- Project name
- var site = 'Sassyjade';
Sets the site name of the project. It can be used with the <title>
-tag for example.
//- Page title format
- var title = site + ' | ' + page;
Sets the global format of the page titles. Above default version would evaluate into something like <title>Sassyjade | Home</title>
. Please note that the page variable can be set on each individual page. This way you can have different titles such as "Home", "About", "Contact" etc. for each template.
//- Project root
- var root = '/path/to/sassyjade/dist/';
Sets the root of the dist/ of the project. If you develop locally you have to pass the full path to the dist/
on your machine. This is helpful to preview your distribution version in a browser. The full path is also needed to create navigations with ease.
//- CSS file to be included in distribution
- var css = root + 'css/main.css';
//- JS file to be included in distribution
- var js = root + 'js/main.js';
Sets the names of the compiled and concatenated css and javascript files in your distribution. Make sure that these paths are the same as your respective options in the sassyjade.config.json
file.
"option": {
"jsName": "main.js",
"cssName": "main.css"
}
The templ/layout/
directory contains the layouts of the project. html.jade
serves as the core structure and should be extended by all other layouts.
Is something like the root layout of all other layouts. Since it defines the doctype and contains the root html tag it should be extended by all other layouts.
Sassyjade uses Jade's block
option to construct layouts. This is convenient because blocks exposed by extended layouts can be overwritten by its child layouts. This leaves more flexibility as opposed to working with includes only.
html.jade
exposes a number of blocks to all layouts that it is extended by.
doctype html
block html
html
block depends
block vars //- use to set variables on pages
include ../incl/config.jade
block head
head
block meta //- use to define meta-tags
include ../incl/aux/meta.jade
block title //- use to set the title-tag
title= title
block stylesheet //- use to link to stylesheets
include ../incl/aux/stylesheet.jade
block body
body
block layout //- use this block to create your layouts
block script //- use to include your scripts
include ../incl/aux/script.jade
Exposes the block "vars" which can be used on every page to set variables available for the whole page. config.jade
is also included here. Note that the variables need to be set before everything else.
Defines the head of the html and by default exposes 3 blocks: "meta", "title" and "stylesheet". The 3 blocks do as they say. By default Sassyjade expects all pages and templates to use the same stylesheets and meta tags. Therefore, for meta-tags and stylesheets include files are used (located at templ/incl/aux
). However, if on one or more sites different ones are needed you can use the respective block to overwrite the defaults.
Represents the actual <body>
-tag of the html. It exposes block layout
and block script
. The latter is similar to the blocks exposed in block "head". Sassyjade thinks you want to include your scripts at the end of the page and expects the same scripts on all pages and templates, hence the include methodology. You can overwrite the block "script" if you need different scripts on different sites.
This is the main block exposed by html.jade
for you to build page layouts. Read in the next paragraph how you might want to do this.
In order to create a new layout extend html.jade
first. This will give you the "layout" block, amongst the other blocks exposed, where you will be able to the define your layout. For example:
extends html.jade
block layout
block header
include ../incl/part/header.jade
block nav
include ../incl/nav/nav.jade
block main
block footer
include ../incl/part/footer.jade
Take note that for Sassyjade a template is a general structure of a page, without any specifics and without any content.
You can define any number of additional blocks in your layout and use includes to reuse components.
To create an actual template you should finally be able to just quickly extend a layout.
extends layout/layout.jade
block vars
- var page= "Home"
block main
//- put custom definitions and content here
Sassyjade sees includes as components, which might be reused in a project in different contexts. Typical examples are navigations, forms or page partials such header/footer.
By default all partials are stored in the templ/incl/par
directory and the navigations at templ/incl/nav
.
The templ/incl/aux
directory contains all auxillary includes such stylesheet.jade or meta.jade (also see here).
MIT © philister16