All Projects → FirebaseExtended → remote-styles

FirebaseExtended / remote-styles

Licence: Apache-2.0 license
Conditionally load CSS from Firebase Remote Config

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to remote-styles

Photos
No description or website provided.
Stars: ✭ 74 (+15.63%)
Mutual labels:  firebase-remote-config
Firebase Android Sdk
Firebase Android SDK
Stars: ✭ 1,704 (+2562.5%)
Mutual labels:  firebase-remote-config
firebase
Modular Firebase 🔥 implementation for NativeScript. Supports both iOS & Android platforms for all Firebase services.
Stars: ✭ 36 (-43.75%)
Mutual labels:  firebase-remote-config

remote-styles

Conditionally load CSS from Firebase Remote Config

Status: Alpha

Install

npm i remote-styles firebase
# OR
yarn add remote-styles firebase

Basic Example

Webpack/Module Bundler usage

import { initialize } from 'remote-styles';

async function importStyles() {
  // Be smart and lazy load. Dynamic styles
  // are not likely needed for page load.
  const firebase = await import('firebase/app');
  await import('firebase/analytics');
  await import('firebase/remote-config');

  const firebaseApp = firebase.initializeApp({ 
    /* config */ 
  });
  const getStyles = await initialize(firebaseApp);
  const styles = getStyles('dark_mode');
  styles.insert();
}

importStyles();

Script Tags / Loader Version

remote-styles has a sub-package that lazy loads Firebase. This is useful for sites that use script tags instad of module bundling.

<body>
  <div class="text-main config-dark">This can be configured remotely!</div>
  <script src="https://unpkg.com/remote-styles/dist/remote-styles-loader.min.js"></script>
  <script>
      (async function(window, remoteStyles) {
        const getStyles = await remoteStyles.initialize({
          /* config */
        });
        const styles = getStyles('dark_mode');
        styles.insert();
      }(window, window.remoteStyles));
  </script>
</body>

Upload/Download CSS from Remote Config via the CLI

To use the CLI you'll need to download a Service Account from the Firebase Console.

Downloading CSS

Downloading CSS currently works only with default parameters.

node_modules/.bin/remote-styles get --key="CSS" --sa="./sa.json" --out="styles.css"

Uploading CSS

Uploading CSS currently works only with default parameters.

node_modules/.bin/remote-styles put --key="CSS" --sa="./sa.json" styles.css
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].