>確保安裝了 npx(npx 在 NPM 版本 5.2.0 默認安裝了):
~~~
npx create-nuxt-app <項目名>
~~~
>或者用 yarn :
~~~
yarn create nuxt-app <項目名>
~~~
>它會讓你進行一些選擇:
1. 在集成的服務器端框架之間進行選擇:
* None (Nuxt 默認服務器)
* [Express](https://github.com/expressjs/express)
* [Koa](https://github.com/koajs/koa)
* [Hapi](https://github.com/hapijs/hapi)
* [Feathers](https://github.com/feathersjs/feathers)
* [Micro](https://github.com/zeit/micro)
* [Fastify](https://github.com/fastify/fastify)
* [Adonis](https://github.com/adonisjs/adonis-framework)(WIP)
2. 選擇您喜歡的 UI 框架:
* None (無)
* [Bootstrap](https://github.com/bootstrap-vue/bootstrap-vue)
* [Vuetify](https://github.com/vuetifyjs/vuetify)
* [Bulma](https://github.com/jgthms/bulma)
* [Tailwind](https://github.com/tailwindcss/tailwindcss)
* [Element UI](https://github.com/ElemeFE/element)
* [Ant Design Vue](https://github.com/vueComponent/ant-design-vue)
* [Buefy](https://github.com/buefy/buefy)
* [iView](https://github.com/iview/iview)
* [Tachyons](https://github.com/tachyons-css/tachyons)
3. 選擇您喜歡的測試框架:
* None (隨意添加一個)
* [Jest](https://github.com/facebook/jest)
* [AVA](https://github.com/avajs/ava)
4. 選擇你想要的 Nuxt 模式 (`Universal`or`SPA`)
5. 添加[axios module](https://github.com/nuxt-community/axios-module)以輕松地將 HTTP 請求發送到您的應用程序中。
6. 添加[EsLint](https://eslint.org/)以在保存時代碼規范和錯誤檢查您的代碼。
7. 添加[Prettier](https://prettier.io/)以在保存時格式化/美化您的代碼。
當運行完時,它將安裝所有依賴項,因此下一步是啟動項目:
~~~
$ cd <project-name>
$ npm run dev
~~~
應用現在運行在 http://localhost:3000 上運行。
注意:Nuxt.js 會監聽`pages`目錄中的文件更改,因此在添加新頁面時無需重新啟動應用程序。
了解模板項目的目錄結構:[目錄結構](https://www.nuxtjs.cn/guide/directory-structure)。
## [](https://www.nuxtjs.cn/guide/installation#%E4%BB%8E%E5%A4%B4%E5%BC%80%E5%A7%8B%E6%96%B0%E5%BB%BA%E9%A1%B9%E7%9B%AE)從頭開始新建項目
如果不使用 Nuxt.js 提供的 starter 模板,我們也可以從頭開始新建一個 Nuxt.js 應用項目,過程非常簡單,只需要*1 個文件和 1 個目錄*。如下所示:
~~~
$ mkdir <項目名>
$ cd <項目名>
~~~
**提示:**將`<項目名>`替換成為你想創建的實際項目名。
### [](https://www.nuxtjs.cn/guide/installation#%E6%96%B0%E5%BB%BA-packagejson-%E6%96%87%E4%BB%B6)新建 package.json 文件
`package.json`文件用來設定如何運行`nuxt`:
~~~
{
"name": "my-app",
"scripts": {
"dev": "nuxt"
}
}
~~~
上面的配置使得我們可以通過運行`npm run dev`來運行`nuxt`。
### [](https://www.nuxtjs.cn/guide/installation#%E5%AE%89%E8%A3%85-nuxt)安裝`nuxt`
一旦`package.json`創建好, 可以通過以下 npm 命令將`nuxt`安裝至項目中:
~~~
npm install --save nuxt
~~~
### [](https://www.nuxtjs.cn/guide/installation#pages-%E7%9B%AE%E5%BD%95)pages 目錄
Nuxt.js 會依據`pages`目錄中的所有`*.vue`文件生成應用的路由配置。
創建`pages`目錄:
~~~
mkdir pages
~~~
創建我們的第一個頁面`pages/index.vue`:
~~~
<template>
<h1>Hello world!</h1>
</template>
~~~
然后啟動項目:
~~~
$ npm run dev
~~~