Getting started with yoeman

The Yeoman workflow is comprised of three core tools for improving your productivity and satisfaction when building a web app. These tools are:html

  • yo - the scaffolding tool from Yeomanhtml5

  • bower - the package management toolnode

  • grunt - the build tooljquery

個人系統:linux deepin 2014.1 桌面版 64位linux

yo

Installing yo and some generatorsgit

First, you'll need to install yo and other required tools:github

sudo npm install -g yo bower

npmnode.js的包管理器,並和它捆綁在一塊兒。web

Basic scaffoldingnpm

爲了搭建一個web應用,你須要安裝一個generator-webappjson

sudo npm install -g generator-webapp

This is the default web application generator that will scaffold out a project containing HTML5 Boilerplate, jQuery, Modernizr, and Bootstrap. You'll have a choice during the interactive prompts to not include many of these.

Now that the generator is installed, create a directory for your new project

mkdir my-yo-project
cd my-yo-project

and then run:

yo webapp

而後就生成一個最簡單的web app了。

Bower

Bower is a package manager for the web which allows you to easily manage dependencies for your projects. This includes assets such as JavaScript, images and CSS. It is maintained by Twitter and the open-source community.

Managing packages using Bower can be done using the following commands:

# Search for a dependency in the Bower registry.
$ bower search <dep>

# Install one or more dependencies.
$ bower install <dep>..<depN>

# List out the dependencies you have installed for a project.
$ bower list

# Update a dependency to the latest version available.
$ bower update <dep>

Using Bower with a project scaffolded using yo

To create a basic web app with a dependency on a jQuery plug-in:

# Scaffold a new application.
$ yo webapp

# Search Bower's registry for the plug-in we want.
$ bower search jquery-pjax

# Install it and save it to bower.json
$ bower install jquery-pjax --save

# If you're using RequireJS...
# (be aware that currently the webapp generator does not include RequireJS and the following command only applies to generators that do)
$ grunt bower
# Injects your Bower dependencies into your RequireJS configuration.

# If you're not using RequireJS...
$ grunt wiredep
# Injects your dependencies into your index.html file.

Your chosen generator may not include the grunt tasks "bower" and "wiredep". You can read more about how to install and use these at grunt-bower-requirejs and grunt-wiredep.

Grunt

Grunt is a task-based command-line tool for JavaScript projects. It can be used to build projects, but also exposes several commands which you will want to use in your workflow. Many of these commands utilize Grunt tasks under the hood which are maintained by the Yeoman team.

Grunt commands

# Preview an app you have generated (with Livereload).
$ grunt serve

# Run the unit tests for an app.
$ grunt test

# Build an optimized, production-ready version of your app.
$ grunt

These commands can be used together with the yo binary for a seamless development workflow:

$ yo webapp
$ grunt serve
$ grunt test
$ grunt
相關文章
相關標籤/搜索