有没有办法在 Angular 中添加基于 firebase 环境的配置?
我有不同的 firebase projectIds 和 messagesSenderIds 用于开发环境和产品环境。我想在我正在为应用程序中的后台通知所做的 firebase_messaging_sw.js 中使用这种不同的配置。下面是代码。
importScripts("https://www.gstatic.com/firebasejs/8.2.7/firebase-app.js");
importScripts("https://www.gstatic.com/firebasejs/8.2.7/firebase-messaging.js");
// For an optimal experience using Cloud Messaging, also add the Firebase SDK for Analytics.
importScripts("https://www.gstatic.com/firebasejs/8.2.7/firebase-analytics.js");
// Initialize the Firebase app in the service worker by passing in the
// messagingSenderId.
firebase.initializeApp({
messagingSenderId: 'xxxxxxxx',
apiKey: 'xxxxxxxxxxxx',
projectId: 'xxxxxxxx',
appId: 'xxxxxxxxxxx',
});
// Retrieve an instance of Firebase Messaging so that it can handle background
// messages.
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function (payload) {
console.log(
"[firebase-messaging-sw.js] …Run Code Online (Sandbox Code Playgroud) javascript service-worker firebase-cloud-messaging angular angular-service-worker