tmerclub-doc/生产环境搭建/tmerclub-pc生产环境搭建.md
2025-03-23 20:32:33 +08:00

117 lines
2.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

> tmerclub-pcpc代表pc端
## 安装nodejs
[NodeJS](https://nodejs.org/) 项目要求最低 18.12.0,推荐 20.9.0
如果不了解怎么安装nodejs的可以参考 [菜鸟教程的nodejs相关](https://www.runoob.com/nodejs/nodejs-install-setup.html)
### 2.安装依赖启动项目
项目要求使用 [pnpm](https://www.pnpm.cn/) 包管理工具
使用编辑器打开项目,在根目录执行以下命令安装依赖
```
pnpm install
```
如果不想使用 pnpm请删除 `package.json` 文件中 `pnpm` 相关内容后再进行安装
```json
{
"scripts" : {
"preinstall": "npx only-allow pnpm" // 删除此行
},
"engines": {
"pnpm": ">=7" // 删除此行
},
"pnpm": { // 删除此项
...
}
}
```
### 3.修改配置文件
修改根目录下的`.env.production`
* 以下域名,接口为示例,请结合申请的域名,接口进行修改
```bash
# 统一接口域名
VITE_APP_BASE_API = 'https://cloud-api.mall4j.com'
# 客服websocket接口请求地址
VITE_APP_WEBSOCKET_URL = 'wss://cloud-api.mall4j.com'
# 移动端域名地址配置 - 用于生成二维码跳转链接
VITE_APP_H5_DOMAIN = 'https://h5.mall4j.com/cloud'
# 图片域名
VITE_APP_RESOURCES_URL = 'https://mall4j-minio-test.mall4j.com/tmerclub'
# 商家端后台地址
VITE_APP_MERCHANT_PLATFORM_URL = 'https://cloud-multishop.mall4j.com'
#供应商端后台地址
VITE_APP_SUPPLIER_PLATFORM_URL = 'https://cloud-supplier.mall4j.com'
```
#### 如需部署在二级目录下,需要修改以下配置
假设部署在 pc 目录,即访问的地址为 https://xxxx.xxx/admin
1. 路由配置 router/index.js
```javascript
const router = createRouter({
// createWebHistory 传入字符串参数目录配置:/目录名/
history: createWebHistory('/pc/'),
})
```
2. 项目配置 vite.config.js
```javascript
export default defineConfig({
// 添加此项配置
base: '/pc/',
})
```
3. nginx 配置
```nginx
location /pc {
try_files $uri $uri/ /pc/;
}
```
### 4.打包,上传到服务器
1. 使用 `npm run build` 命令对项目进行打包
2. 将步骤1中生成的文件夹压缩
3. 将压缩包上传到服务器指定位置,解压
### 5. nginx配置
nginx配置可以参考
```nginx
location / {
try_files $uri $uri/
}
```