Skip to content

Instantly share code, notes, and snippets.

@patrickkettner
Last active October 6, 2023 19:54
Show Gist options
  • Save patrickkettner/8c1a91b1b8f9502b3b67d874e7024a7b to your computer and use it in GitHub Desktop.
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
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