AngularUniversal+Firebase云函数部署问题
创始人
2024-10-29 20:30:52
0
  1. 在项目根目录创建firebase.json文件,包含以下内容:
{
    "hosting": {
        "public": "dist/browser",
        "rewrites": [{
            "source": "**",
            "function": "universal"
        }]
    },
    "functions": {
        "source": "dist/server",
        "predeploy": [
            "npm --prefix \"$RESOURCE_DIR\" run build",
            "npm --prefix \"$RESOURCE_DIR\" run compile"
        ],
        "deploy": {
            "memory": "1GB",
            "timeout": "60s"
        }
    },
    "emulators": {
        "functions": {
            "port": 5001
        },
        "hosting": {
            "port": 5000
        }
    }
}
  1. 在项目根目录下创建 tsconfig.server.json 文件,包含以下内容:
{
    "extends": "./tsconfig.app.json",
    "compilerOptions": {
        "outDir": "./out-tsc/server",
        "baseUrl": "./",
        "module": "commonjs",
        "types": []
    },
    "exclude": [
        "src/test.ts",
        "**/*.spec.ts"
    ],
    "angularCompilerOptions": {
        "entryModule": "./src/app/app.server.module#AppServerModule"
    }
}
  1. package.json的scripts中添加以下内容:
"serve:universal": "firebase serve --only functions,hosting",
"build:universal": "npm run build:client-and-server-bundles && npm run compile:server",
"build:client-and-server-bundles": "ng build --prod && ng run myapp:server:production",
"compile:server": "tsc -p server.tsconfig.json",
"deploy:universal": "firebase deploy --only functions,hosting"
  1. 在项目根目录下运行以下命令:
npm install firebase-tools --save-dev

npm install -g firebase-tools
  1. 在Firebase控制台中创建一个项目。

  2. 允许Firestore和Functions服务。

  3. 使用以下命令将本地项目与云端项目进行连接:

firebase login
firebase init
  1. 依次选择 Hosting, Functions 和 Firestore, 输入相关配置信息。

  2. app.server.module 文件内容修改为:

import { NgModule } from '@angular/core';
import { ServerModule } from '@angular/platform-server';
import { ModuleMapLoaderModule } from '@nguniversal/module-map-ngfactory-loader';
import { AppModule } from './app.module';
import { AppComponent } from './

相关内容

热门资讯

透视免费!hhpoker辅助器... 透视免费!hhpoker辅助器,wpk德州局怎么透视,必赢教程(原来真的是有挂);大神普及一款德州a...
透视线上!wpk透视辅助靠谱吗... 透视线上!wpk透视辅助靠谱吗,wepoker透视app下载,安装教程(固有有挂)1、点击下载安装,...
透视玄学!智星菠萝辅助,wep... 透视玄学!智星菠萝辅助,wepoker有机器人吗,2025新版教程(竟然是有挂);小薇(透视辅助)致...
透视插件!德普之星透视辅助io... 透视插件!德普之星透视辅助ios,we-poker辅助器,详细教程(果然是真的有挂)1、许多玩家不知...
透视黑科技!德普之星透视辅助,... 《透视黑科技!德普之星透视辅助,佛手大菠萝有挂吗,玩家教程(原生存在有挂)》 德普之星透视辅助软件透...
透视透视!wpk辅助购买,aa... 透视透视!wpk辅助购买,aa poker透视软件,新2025教程(原先有挂);原来确实真的有挂(需...
透视科技!aapoker辅助是... 透视科技!aapoker辅助是真的吗,哈糖大菠萝攻略,详细教程(原先存在有挂);科技详细教程Q群《1...
透视app!hhpoker万能... 透视app!hhpoker万能辅助器,wepoker私人局辅助挂,科技教程(原生有挂)是一款可以让一...
透视安卓版!wpk透视工作室,... 透视安卓版!wpk透视工作室,wepoker透视脚本免费下载,必备教程(切实是有挂);科技安装教程;...
透视新版!wepoker透视脚... 透视新版!wepoker透视脚本免费下载,wepoker辅助透视软件,技巧教程(固有是真的有挂);致...