Skip to content

Add CJS build for messaging/sw #5884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slow-bobcats-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/messaging': patch
---

Add a CJS bundle for messaging/sw. This enables some SSR frameworks to run their Node.js pipelines without erroring.
7 changes: 6 additions & 1 deletion packages/messaging/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"browser": "dist/esm/index.esm2017.js",
"module": "dist/esm/index.esm2017.js",
"sw": "dist/index.sw.esm2017.js",
"sw-main": "dist/index.sw.cjs",
"esm5": "dist/esm/index.esm.js",
"exports": {
".": {
Expand All @@ -15,7 +16,11 @@
"esm5": "./dist/esm/index.esm.js",
"default": "./dist/index.cjs.js"
},
"./sw": "./dist/index.sw.esm2017.js",
"./sw": {
"require": "./dist/index.sw.cjs",
"import": "./dist/index.sw.esm2017.js",
"default": "./dist/index.sw.esm2017.js"
},
"./package.json": "./package.json"
},
"typings": "dist/src/index.d.ts",
Expand Down
14 changes: 14 additions & 0 deletions packages/messaging/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ const cjsBuilds = [
replace(generateBuildTargetReplaceConfig('cjs', 5))
],
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},
// sw build
// TODO: This may no longer be necessary when we can provide ESM Node
// builds (contingent on updating the `idb` dependency). When we add
// ESM Node builds, test with Nuxt and other SSR frameworks to see if
// this can then be removed.
{
input: 'src/index.sw.ts',
output: { file: pkg['sw-main'], format: 'cjs', sourcemap: true },
plugins: [
...es5BuildPlugins,
replace(generateBuildTargetReplaceConfig('cjs', 5))
],
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];

Expand Down
1 change: 1 addition & 0 deletions packages/messaging/sw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@firebase/messaging-sw",
"description": "",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"main": "../dist/index.sw.cjs",
"module": "../dist/index.sw.esm2017.js",
"typings": "../dist/src/index.sw.d.ts"
}