-
-
Save patrickkettner/8c1a91b1b8f9502b3b67d874e7024a7b to your computer and use it in GitHub Desktop.
inline firestore sdk in order to load it without remote deps at runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { existsSync } from 'fs'; | |
import fetch from 'node-fetch'; | |
const REMOTE_FIREBASE_URL = 'https://www.gstatic.com/firebasejs/9.15.0/'; | |
export default { | |
plugins: [{ | |
transform: function transform(code, id) { | |
return code.replace(/\.\/firebase\//g, REMOTE_FIREBASE_URL) | |
}, | |
resolveDynamicImport: function(importee) { | |
if (!existsSync(importee)) { | |
return importee | |
} | |
}, | |
load: async function transform(id, options, outputOptions) { | |
if (!existsSync(id)) { | |
const response = await fetch(id); | |
const code = await response.text(); | |
return code | |
} | |
return null | |
} | |
}, | |
{ | |
resolveId: function(importee, importer, options) { | |
if (!importer) { | |
return null | |
} | |
return importee | |
} | |
} | |
], | |
output: { | |
inlineDynamicImports: true | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment