Coder Social home page Coder Social logo

entria / react-app-loader Goto Github PK

View Code? Open in Web Editor NEW
75.0 20.0 2.0 650 KB

Production ready library for handling Microfrontends

Home Page: https://entria.github.io/react-app-loader/

License: MIT License

HTML 14.52% JavaScript 85.48%
react app apploader microfrontends hoc higher-order-component react-dom

react-app-loader's Introduction

react-app-loader github

Production ready library for handling Microfrontends.

Preview

How to use

Create a config file for each external app:

$ touch AnyExternalApp.js

Then, wrap it with withAppLoader HOC:

// @flow

import withAppLoader from '@entria/react-app-loader';

const elementId = 'github';
const appUrl = 'https://github.com/';

const AppLoader = withAppLoader({ elementId, appUrl });

export default AppLoader;

Or you can try a more complex way, passing some props:

// @flow

import React from 'react';
import withAppLoader from '@entria/react-app-loader';

const elementId = 'github';
const appUrl = 'https://github.com/';

type Props = {
  externalUrl: string,
};

const AnyExternalApp = (props: Props) => {
  const { externalUrl } = props;
  const AppLoader = withAppLoader({
    elementId,
    appUrl: externalUrl != null && externalUrl.length > 0 ? externalUrl : appUrl
  });
  return <AppLoader />;
};

export default AnyExternalApp;

Import it on your React app:

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';

import AnyExternalApp from './AnyExternalApp';

class App extends Component {
  render() {
    return (
      <div className="App">
        <AnyExternalApp />
      </div>
    );
  }
}

export default App;

Import babel-polyfill on your index.js

import 'babel-polyfill';

Run \o/

Handling cors during development

On Google Chrome, just install this extension: https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi

License

MIT

react-app-loader's People

Contributors

jgcmarins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-app-loader's Issues

webpack instances conflicts

If you have different versions of webpack in your apps, it could run in some troubles

How to fix it

output: { 
   jsonpFunction: 'appJsonpFunction' 
}

babel-polyfill conflicts

  • babel-polyfill

If another app also adds babel-polyfill it will cause troubles

Uncaught Error: only one instance of babel-polyfill is allowed
    at Object.eval (VM14221 index.js:10)
    at eval (VM14221 index.js:29)
    at Object../node_modules/babel-polyfill/lib/index.js

How to improve script load performance

I was thinking about how to improve the performance of the scripts in my applications.

I currently have several applications using React.

My idea is the root application load the libraries together and the loaded application only provides the app script.

Is that a valid idea? Has anyone had success or failures at this point?

Improve README

Add more information and examples:

  • Add a working example with React Router
  • Add an example with LoadingComponent
  • Add an example with shared authentication layer
  • Add an example with shared style
  • Add an example with more complex props and state
  • More informaton about development setup (handling cors, etc)
  • Relay?
  • Redux?

fix gh pages demo cors

Failed to load https://github.com/: No 'Access-Control-Allow-Origin' header is present on the
 requested resource. Origin 'https://entria.github.io' is therefore not allowed access.

screen shot 2018-04-02 at 16 50 43

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.