- Ember.js Cookbook
- Erik Hanchett
- 1096字
- 2021-07-16 12:57:59
Installing Ember CLI
The installation of Ember CLI is essential to learning Ember and will be used throughout this book.
Getting ready
Before the installation of Ember CLI, we must have the Node Package Manager (npm) installed. npm
is a package manager for JavaScript and is installed by default with Node.js.
You must install version 0.12 or later of Node.js for Ember CLI to run. If you can, try to install version 4.0.0 or higher. This is the preferred version.
Node.js is available in several major platforms including Windows, Mac, and Linux. There are several ways to install Node.js:
- One-click installers: Many platforms such as Windows and Mac have this available
- Homebrew or MacPorts: This is useful for Mac OS users
- Download TAR file: Download a TAR file of Node.js and extract
- Install via the Linux package management system: Yum, apt-get, or pacman can be used to install on a Linux environment
A one-click installer for Windows or Mac
This method is by far the easiest. To install node, you'll need to open the node website at http://nodejs.org/download. Click on the pkg
, msi
, or exe
installer for Windows or Mac. Run it after it's downloaded.
Homebrew or MacPorts for Mac
If you already have Homebrew installed, just run the following command:
$ brew install node
On the other hand, if you are running MacPorts, you can use the port install command:
$ sudo port install nodejs
Tip
MacPorts can be installed from http://www.macports.org. Homewbrew can be installed from http://brew.sh. Both offer simple package management for OS X systems.
A TAR file
A TAR file is a type of archive file. To install node via a TAR, you will need to download the TAR file from the Node.js website and extract and install it. One way of doing this is to use curl
.
I would only recommend this method if you are using a Linux distribution. If you are running on Linux, you'll need the right tools installed to compile from source. On Ubuntu, you'll need to install the build-essential and curl
packages:
$ curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1 $ ./configure $ sudo make install
The Linux package manager
All major Linux distributions offer Node.js packages. In Ubuntu, you can simply use apt-get
:
$ sudo apt-get install nodejs
In Fedora, you can use yum
:
$ yum install nodejs npm
Check with your Linux distribution to find out more details on how to install packages such as Node.js. Be aware that some distributions might offer outdated versions of Node.js. In this case, I would recommend that you use the Node Version Manager (NVM) installation method that will be discussed later.
Test installation
To test your installation, run the –v
command:
$ node –v $ npm –v
This will show the current installed version. Keep in mind that you must run v0.12 or above to run Ember CLI. If possible, try to run v4.0.0 or above.
Tip
The NVM is a bash script that helps manage multiple active Node.js versions. NVM offers a very simple command-line interface to install any version of Node.js without having to visit the Node.js website. It separates each installation making it very easy to change between versions. I would recommend most beginners on Mac and Linux to run this. You can download NVM at https://github.com/creationix/nvm.
How to do it...
We'll need to use npm
to install Ember CLI. We'll install it globally with the –g
option so that it can be run anywhere from the command line.
- Open the command prompt and type the following command:
$ sudo npm install –g ember-cli
If NVM was installed, you don't need
sudo
at the start of the command. - After Ember CLI is installed, we'll need to download Bower. Bower is a package manager for client-side programming and another essential component of Ember.js. Node.js and npm must be installed before beginning the installation of Bower. We'll be using Bower to install all our client-side libraries:
$ sudo npm install –g bower
Similar to the last command, you don't need
sudo
at the start of the command if Node.js was installed via NVM. - The last step is to install PhantomJS. PhantomJS is a scripted headless browser used to automate and test web pages. It's preferred by Ember CLI and needs to be installed:
$ npm install –g phantomjs
- If you are on Windows, install the Ember CLI Windows tool:
$ npm install ember-cli-windows –g
- Once installed, this tool can be run in any project directory:
$ ember-cli-windows
- Make sure to download and install Git for Windows: https://git-scm.com/downloads
Note
Working with Windows
Build times on Windows can be longer then Mac or Linux. The Ember CLI Windows tool can help speed up and optimize build performance. Just run it in the project directory. You can also download it as an add-on instead.
Another way to help with performance is to always run PowerShell/CMD with elevated privileges. Otherwise, performance issues and errors might occur. Lastly, try to use npm version 3 or higher. You may run into issues with long file paths with older versions in Windows.
Another handy tip is as follows:
Tip
Optional: Install Watchman
Watchman is a file-watching service for OS X and UNIX-like operating systems. It was developed by Facebook and is a more effective way for Ember CLI to watch project changes. If it's not installed, Ember CLI will fall back to using NodeWatcher. NodeWatcher is more error-prone and has trouble observing large trees. Install Watchman if your platform supports it. To download and configure Watchman, visit https://facebook.github.io/watchman/.
How it works...
Ember CLI is written in Node.js and can be installed via npm. The tool interprets commands from the user to help create an Ember.js application. Each command from the user is looked up and then executed. Ember CLI relies on several other dependencies including Bower, Lodash, Broccoli, and Babel, to name a few.
There's more...
Let's take a look at commands and aliases.
Commands
Once Ember CLI is installed, we'll have access to several commands. Here is a short list of some of the more important ones:
Aliases
Keep in mind that for every command, there is an alias. These aliases make it a little quicker to run commands. Suppose that you wanted to build a new project. Normally, you would type this:
$ ember build
This will work and is fine. It will generate a new project and application structure. You can also use an alias.
$ ember b
Here is a list of some common aliases that you can use. This is optional.
- UI設計基礎培訓教程
- Java Web開發學習手冊
- 機械工程師Python編程:入門、實戰與進階
- 青少年信息學競賽
- Java編程的邏輯
- HTML5與CSS3基礎教程(第8版)
- Statistical Application Development with R and Python(Second Edition)
- 深入解析Java編譯器:源碼剖析與實例詳解
- INSTANT Apache Hive Essentials How-to
- Android 游戲開發大全(第二版)
- 深入淺出 HTTPS:從原理到實戰
- HTML5 Canvas核心技術:圖形、動畫與游戲開發
- Android熱門應用開發詳解
- Learning C# by Developing Games with Unity 3D Beginner's Guide
- 微信小程序開發圖解案例教程:附精講視頻(第3版)