概要
前回はフォルダを作成してその中に必要ファイルをコピーしていた。
今回はBundleすることによりその手間を減らすこととする。
ソースコード
ビルドスクリプトをesbuildを使ったものに修正。
@azure/functions-core
はexternalに指定しないとエラーとなる。
apps/api/package.json
{
"name": "@async-ttrpg/api",
"version": "0.0.0",
"description": "",
"scripts": {
"prebuild": "npm run clean && npm run prisma-generate",
+ "build": "esbuild src/functions/index.ts --bundle --platform=node --target=node20 --outdir=dist/src/functions --external:@azure/functions-core --minify",
"watch": "tsc -w",
"clean": "rimraf dist",
"predev": "npm run build",
"dev": "func start --port 7071",
"lint": "eslint",
"prisma-pull-local": "dotenv -e .env.local -- bash -c 'npx prisma db pull'",
"prisma-pull": "prisma db pull",
"prisma-generate": "prisma generate",
+ "predeploy": "npm run build",
+ "deploy": "dotenv -e .env -- bash -c 'func azure functionapp publish $APP_NAME --subscription $AZURE_SUBSCRIPTION_ID'",
"ncu": "ncu -u"
},
"dependencies": {
"@azure/functions": "^4.5.1",
"@azure/identity": "^4.4.1",
"@azure/storage-blob": "^12.25.0",
"@azure/storage-queue": "^12.24.0",
"@hono/swagger-ui": "^0.4.1",
"@hono/zod-openapi": "^0.16.2",
"@marplex/hono-azurefunc-adapter": "^1.0.0",
"@prisma/client": "^5.20.0",
"date-fns": "^4.1.0",
"hono": "^4.6.3",
"mssql": "^11.0.1",
"zod": "^3.23.8"
},
"devDependencies": {
"@async-ttrpg/eslint-config-custom": "*",
"@async-ttrpg/tsconfig": "*",
"@types/mssql": "^9.1.5",
"@types/node": "^22.7.3",
"dotenv-cli": "^7.4.2",
"esbuild": "^0.24.0",
"prisma": "^5.20.0",
"rimraf": "^6.0.1",
"typescript": "^5.6.2",
"zod-prisma-types": "^3.1.8"
},
"optionalDependencies": {
"@rollup/rollup-linux-x64-gnu": "^4.22.5"
},
"main": "dist/src/{app.js,functions/*.js}"
}
バンドルの対象ファイルを作成
apps/api/src/functions/index.ts
import './httpTrigger';
import './openAPI';
import './queueTrigger';
node_modulesはバンドルされた結果不要になるのでignoreに追加。
apps/api/.funcignore
*.js.map
*.ts
.git*
.vscode
__azurite_db*__.json
__blobstorage__
__queuestorage__
local.settings.json
test
tsconfig.json
.turbo
.env
.env.sample
+ node_modules