vercel.json
builds
主要用于定义部署过程中的构建步骤,特别是应用不是通过简单的静态文件部署,而是需要编译、打包或配置特定环境时。
使用一个数组表示:
Array
构造是提供:
src
:全局表达式,或者路径名.如果要解析多个文件,要为每个匹配的文件创建一个构造,包含*,**
use
: 要安装的npm
模块config
: 可包含传递给构造器的任意元数据的对象.
@vercel/python
: 使用vercel
提供的Python
版本
@vercel/static
: 预设的构建和部署插件,专门用于处理静态网站.使用这个选项可以自动化构造,优化部署,简化配置.{ "builds": [{ "src": "app.py", // 你的源代码目录 "use": "@vercel/python", // 使用 Vercel 提供的 Flask 部署插件 "config": { "command": "flask build", // 部署时执行的命令,用于构建和静态化应用 "env": { "FLASK_APP": "app.py", // 你的Flask应用主文件 "FLASK_ENV": "production" // 运行环境,这里设置为生产环境 } } }] }
routes
定义如何处理传入的 URL
src: A PCRE-compatible regular expression that matches each incoming pathname (excluding querystring). methods: A set of HTTP method types. If no method is provided, requests with any HTTP method will be a candidate for the route. dest: A destination pathname or full URL, including querystring, with the ability to embed capture groups as $1, $2… headers: A set of headers to apply for responses. status: A status code to respond with. Can be used in tandem with Location: header to implement redirects. continue: A boolean to change matching behavior. If true, routing will continue even when the src is matched. has: An optional array of has objects with the type, key and value properties. Used for conditional path matching based on the presence of specified properties missing: An optional array of missing objects with the type, key and value properties. Used for conditional path matching based on the absence of specified properties
"routes": [ { "src": "/(.*)", "dest": "app.py" } ]