2021-01-19 21:13:13 +08:00
|
|
|
|
# 快速上手
|
|
|
|
|
|
|
|
|
|
## 依赖环境
|
2021-03-01 12:13:48 +08:00
|
|
|
|
首先得有 [Node.js](https://nodejs.org/),并确保 node 版本是 10.13 或以上。
|
|
|
|
|
```bash
|
|
|
|
|
# 打印 node 版本
|
|
|
|
|
node -v
|
|
|
|
|
v10.13.0
|
|
|
|
|
```
|
|
|
|
|
推荐使用 yarn 管理 npm 依赖
|
|
|
|
|
```bash
|
|
|
|
|
# 全局安装 yarn
|
|
|
|
|
npm i yarn -g
|
|
|
|
|
```
|
2021-01-19 21:13:13 +08:00
|
|
|
|
|
2021-03-07 12:40:57 +08:00
|
|
|
|
## 创建项目
|
2021-01-19 21:13:13 +08:00
|
|
|
|
|
2021-03-01 12:13:48 +08:00
|
|
|
|
这一章节会帮助你从头搭建一个简单的 Fes.js 前端应用。
|
2021-01-19 21:13:13 +08:00
|
|
|
|
|
2021-03-01 12:13:48 +08:00
|
|
|
|
##### 步骤1 创建工作空间
|
2021-03-07 12:40:57 +08:00
|
|
|
|
如果工作空间不存在,则先创建:
|
2021-01-19 21:13:13 +08:00
|
|
|
|
```bash
|
2021-03-01 12:13:48 +08:00
|
|
|
|
# 创建目录 workspace
|
|
|
|
|
mkdir workspace
|
|
|
|
|
# 进入目录 workspace
|
|
|
|
|
cd workspace
|
|
|
|
|
```
|
2021-03-07 12:40:57 +08:00
|
|
|
|
如果工作空间已存在,则直接进入
|
2021-03-01 12:13:48 +08:00
|
|
|
|
```bash
|
|
|
|
|
# 进入目录 workspace
|
|
|
|
|
cd workspace
|
2021-01-19 21:13:13 +08:00
|
|
|
|
```
|
|
|
|
|
|
2021-03-07 12:40:57 +08:00
|
|
|
|
##### 步骤2 在工作空间创建项目
|
2021-01-19 21:13:13 +08:00
|
|
|
|
<CodeGroup>
|
|
|
|
|
<CodeGroupItem title="YARN" active>
|
|
|
|
|
|
|
|
|
|
```bash
|
2021-03-01 12:13:48 +08:00
|
|
|
|
# 创建模板
|
2021-03-05 18:58:14 +08:00
|
|
|
|
yarn create @fesjs/fes-app myapp
|
2021-01-19 21:13:13 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</CodeGroupItem>
|
|
|
|
|
|
|
|
|
|
<CodeGroupItem title="NPM">
|
|
|
|
|
|
|
|
|
|
```bash
|
2021-03-01 12:13:48 +08:00
|
|
|
|
# 创建模板
|
2021-03-05 18:58:14 +08:00
|
|
|
|
npx @fesjs/create-fes-app myapp
|
2021-01-19 21:13:13 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</CodeGroupItem>
|
|
|
|
|
</CodeGroup>
|
|
|
|
|
|
|
|
|
|
|
2021-03-07 12:40:57 +08:00
|
|
|
|
如果项目文件夹 `workspace/myapp` 已经存在,会提示目录已存在:
|
|
|
|
|
|
2021-03-06 15:22:09 +08:00
|
|
|
|
<img :src="$withBase('pickTemplateTip.png')" alt="目录已存在提示">
|
2021-03-01 12:13:48 +08:00
|
|
|
|
|
2021-03-07 12:40:57 +08:00
|
|
|
|
你可以选择:
|
|
|
|
|
- `Overwrite` 删除项目文件夹,重新创建项目。
|
|
|
|
|
- `Merge` 保留原项目文件夹,存在相同文件则用模板文件覆盖当前目录文件。
|
2021-03-02 19:22:01 +08:00
|
|
|
|
|
2021-03-07 12:40:57 +08:00
|
|
|
|
当选择 `Overwrite` 或者 `Merge` 或者项目目录 `workspace/myapp` 不存在,会提示选取一个 `template`:
|
2021-03-06 15:22:09 +08:00
|
|
|
|
<img :src="$withBase('pickTemplate.png')" alt="选择模板类型">
|
2021-01-19 21:13:13 +08:00
|
|
|
|
|
2021-03-07 12:40:57 +08:00
|
|
|
|
你可以选默认适用于中后台前端应用的 `PC` 类型,也可以选适用于移动端的 `H5` 类型。
|
|
|
|
|
|
|
|
|
|
|
2021-03-01 12:13:48 +08:00
|
|
|
|
##### 步骤3 安装依赖
|
2021-01-19 21:13:13 +08:00
|
|
|
|
<CodeGroup>
|
|
|
|
|
<CodeGroupItem title="YARN" active>
|
|
|
|
|
|
|
|
|
|
```bash
|
2021-03-01 12:13:48 +08:00
|
|
|
|
# 进入项目目录
|
|
|
|
|
cd myapp
|
|
|
|
|
# 安装依赖
|
|
|
|
|
yarn
|
2021-01-19 21:13:13 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</CodeGroupItem>
|
|
|
|
|
|
|
|
|
|
<CodeGroupItem title="NPM">
|
|
|
|
|
|
|
|
|
|
```bash
|
2021-03-01 12:13:48 +08:00
|
|
|
|
# 进入项目目录
|
|
|
|
|
cd myapp
|
|
|
|
|
# 安装依赖
|
|
|
|
|
npm i
|
2021-01-19 21:13:13 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</CodeGroupItem>
|
|
|
|
|
</CodeGroup>
|
|
|
|
|
|
2021-03-01 12:13:48 +08:00
|
|
|
|
## 启动项目
|
|
|
|
|
<CodeGroup>
|
|
|
|
|
<CodeGroupItem title="YARN" active>
|
2021-01-19 21:13:13 +08:00
|
|
|
|
|
2021-03-01 12:13:48 +08:00
|
|
|
|
```bash
|
|
|
|
|
# 开发调试
|
|
|
|
|
yarn dev
|
2021-01-19 21:13:13 +08:00
|
|
|
|
|
2021-03-01 12:13:48 +08:00
|
|
|
|
yarn run v1.22.4
|
|
|
|
|
$ fes dev
|
|
|
|
|
Starting the development server http://localhost:8080 ...
|
2021-01-19 21:13:13 +08:00
|
|
|
|
|
2021-03-01 12:13:48 +08:00
|
|
|
|
✔ Webpack
|
|
|
|
|
Compiled successfully in 15.91s
|
|
|
|
|
|
|
|
|
|
DONE Compiled successfully in 15917ms 11:17:08 AM
|
2021-01-19 21:13:13 +08:00
|
|
|
|
```
|
|
|
|
|
|
2021-03-01 12:13:48 +08:00
|
|
|
|
</CodeGroupItem>
|
|
|
|
|
|
|
|
|
|
<CodeGroupItem title="NPM">
|
2021-01-19 21:13:13 +08:00
|
|
|
|
|
|
|
|
|
```bash
|
2021-03-01 12:13:48 +08:00
|
|
|
|
# 开发调试
|
|
|
|
|
npm run dev
|
|
|
|
|
|
|
|
|
|
> fes dev
|
|
|
|
|
Starting the development server http://localhost:8080 ...
|
|
|
|
|
|
|
|
|
|
✔ Webpack
|
|
|
|
|
Compiled successfully in 3.66s
|
|
|
|
|
|
|
|
|
|
DONE Compiled successfully in 3662ms 11:17:46 AM
|
2021-01-19 21:13:13 +08:00
|
|
|
|
```
|
|
|
|
|
|
2021-03-01 12:13:48 +08:00
|
|
|
|
</CodeGroupItem>
|
|
|
|
|
</CodeGroup>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Fes.js 会在 [http://localhost:8080](http://localhost:8080) 启动一个热重载的开发服务器。当你修改你的 .vue 文件时,浏览器中的内容也会自动更新。
|
|
|
|
|
|
|
|
|
|
|
2021-03-07 12:40:57 +08:00
|
|
|
|
<img :src="$withBase('home.png')" alt="home">
|
2021-01-19 21:13:13 +08:00
|
|
|
|
|
2021-03-01 12:13:48 +08:00
|
|
|
|
## 部署发布
|
|
|
|
|
|
|
|
|
|
### 构建
|
2021-01-19 21:13:13 +08:00
|
|
|
|
<CodeGroup>
|
|
|
|
|
<CodeGroupItem title="YARN" active>
|
|
|
|
|
|
|
|
|
|
```bash
|
2021-03-01 12:13:48 +08:00
|
|
|
|
# 构建
|
|
|
|
|
yarn build
|
|
|
|
|
|
|
|
|
|
yarn run v1.22.4
|
|
|
|
|
$ fes build
|
|
|
|
|
|
|
|
|
|
✔ Webpack
|
|
|
|
|
Compiled successfully in 45.37s
|
|
|
|
|
|
|
|
|
|
✨ Done in 48.87s.
|
2021-01-19 21:13:13 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</CodeGroupItem>
|
|
|
|
|
|
|
|
|
|
<CodeGroupItem title="NPM">
|
|
|
|
|
|
|
|
|
|
```bash
|
2021-03-01 12:13:48 +08:00
|
|
|
|
# 构建
|
|
|
|
|
npm run build
|
|
|
|
|
|
|
|
|
|
> fes build
|
|
|
|
|
|
|
|
|
|
✔ Webpack
|
|
|
|
|
Compiled successfully in 45.37s
|
2021-01-19 21:13:13 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</CodeGroupItem>
|
|
|
|
|
</CodeGroup>
|
|
|
|
|
|
2021-03-01 12:13:48 +08:00
|
|
|
|
构建产物默认生成到 ./dist 下,然后通过 tree 命令查看。
|
|
|
|
|
```base
|
|
|
|
|
tree ./dist
|
|
|
|
|
|
|
|
|
|
dist
|
|
|
|
|
├── chunk-vendors.27cd4686.js
|
|
|
|
|
├── chunk-vendors.a5f5de67.css
|
|
|
|
|
├── index.11411d43.css
|
|
|
|
|
├── index.d72f1ba2.js
|
|
|
|
|
├── index.html
|
|
|
|
|
├── logo.png
|
|
|
|
|
└── static
|
|
|
|
|
└── logo.0f85bba0.png
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 本地验证
|
2021-03-07 12:40:57 +08:00
|
|
|
|
发布之前,可以通过 [serve](https://github.com/vercel/serve) 做本地验证,验证结果应该跟执行 `fes dev` 的结果一样。
|
2021-03-01 12:13:48 +08:00
|
|
|
|
|
2021-01-19 21:13:13 +08:00
|
|
|
|
|
2021-03-01 12:13:48 +08:00
|
|
|
|
### 部署
|
|
|
|
|
本地验证完,就可以部署了。你需要把 dist 目录部署到服务器上。
|