GithubHelp home page GithubHelp logo

isabella232 / remote-styles Goto Github PK

View Code? Open in Web Editor NEW

This project forked from firebaseextended/remote-styles

0.0 0.0 0.0 2.82 MB

Conditionally load CSS from Firebase Remote Config

License: Apache License 2.0

JavaScript 31.90% TypeScript 57.44% HTML 10.66%

remote-styles's Introduction

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

remote-styles's People

Contributors

davideast avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.