Yeoman is a command line tool that allows us to easily build web applications.
We'll be using it in conjunction with a few other tools as a part of our development toolchain.
$ npm install -g yo bower gulp
Before we get started we'll need to ensure we have our tools installed.
Assuming you already have npm, run the following command to grab Yeoman, Bower & Gulp. If you have one or more of these, only install the ones you don't have.
// install generator
$ npm install -g generator-gulp-webapp
// create a new directory
$ mkdir aaa-yo
$ cd aaa-yo
// verify that the generator exists
$ yo --help
// generate a new app
$ yo gulp-webapp
Now we'll create a home for our application, make sure we're inside that folder and then run the yo command.
I selected Bootstrap, Sass and Modernizr. "Y" to libsass!
The build may take a while because of all the awesome happening behind the scenes (we'll get to that shortly). In the end you'll have a fully scaffolded web app!
$ gulp serve
To start the server run:
Your app should open automatically in a browser window at localhost:9000
Let's peak into a few files and folders inside our shiny new application.
app: a parent directory for our web application
index.html: the base html file for our app
favicon.ico, and robots.txt: commonly used web files so you don’t have to create them yourself
scripts:
main.js: our main application JavaScript code
styles:
main.scss: our Sass file
bower_components, bower.json: our JavaScript/web dependencies, installed by Bower
gulpfile.js, package.json, and node_modules: configuration and dependencies required by our gulp tasks
This might be my favorite part of Yeoman's generated goodies.
Live reload allows us to make changes to any of our app files and automatically see updates on localhost WITHOUT refreshing the page.
To see live reload in action make a small change in the stylesheet and save it.
/* app/styles/main.scss */
body {
padding-top: 20px;
padding-bottom: 20px;
background: black;
}
Then take a look at your terminal window. Your app compiles automatically.
Now open take a look in the browser.