package.json中配置
"scripts": {
"build:dev": "cross-env UMI_ENV=development max build",
"build:prod": "cross-env UMI_ENV=production max build",
"dev": "max dev",
"format": "prettier --cache --write .",
"postinstall": "max setup",
"prepare": "husky",
"setup": "max setup",
"start": "npm run dev"
}
在src目录下创建文件
注意:文件名称必须写正确development和production 否则打包出来环境变量不正确
文件名称要和package.json中一致
文件内容
import { defineConfig } from '@umijs/max';
export default defineConfig({
antd: {},
access: {},
model: {},
initialState: {},
request: {},
layout: {
title: '管理平台',
},
routes: [],
npmClient: 'pnpm',
define: {
'process.env': {
API_HOST: '//www.com' //后端地址
},
},
});
使用
使用示例