Coder Social home page Coder Social logo

sjcproduction / helium.js Goto Github PK

View Code? Open in Web Editor NEW
63.0 3.0 3.0 3.77 MB

Automating Universal React Applications

License: MIT License

JavaScript 100.00%
javascript isomorphic universal-react react react-router-v4 redux helium optimization universal-javascript universal

helium.js's Introduction

alt text

Making your React application lighter! 🎈

npm dependencies NSP Status Codacy Badge GitHub stars License: MIT contributions welcome

What is Helium.js?

Helium.js is a node package that helps make your React application isomorphic and optimized.

Leveraging server-side rendering can significantly improve first page load performance: render JavaScript templates on the server to deliver fast first render, and then use client-side templating once the page is loaded. However, performance benefits depend on the use case and server-side rendering is not a one size fits all design.

  • Currently:
    • Includes server side rendering with support for React Router v4 and Redux v3 using React Fiber - v16
    • Perfomance metrics CLI
  • Coming Soon: Optimization for webpack bundles

Table of Contents

Installation

Prerequisites

You will need to have react 16/react-dom, the babel-cli, and two babel presets: env and react installed as dependencies.

$ npm install --save react react-dom babel-cli babel-preset-env babel-preset-react

Local Installation

$ npm install --save helium.js

Global Installation

You can additionally install globally for direct usage of CLI commands in your terminal.

$ npm install -g --save helium.js

Usage

Hydrating on Client Side

/* Replace render with helium method
inside the index file of React application */

import helium from 'helium.js/react';

helium(
  <BrowserRouter>
    <App/>
  </BrowserRouter>, 
  'root' 
);

(with Redux)

/* Replace render with helium method
inside the index file of React application */

import helium, { getStore } from 'helium.js/react';

// import your reducer

helium(
  <Provider store={ getStore(reducer) }>
    <BrowserRouter>
      <App/>
    </BrowserRouter>
  </Provider>,
  'root' 
);

(with Redux and Middlewares)

/* Replace render with helium method
inside the index file of React application.
Declare your middlewares as usual and pass 
in as a second parameter to getStore invocation */

import helium, { getStore } from 'helium.js/react';

// import your reducer
// declare your middlewares

helium(
  <Provider store={ getStore(reducer, middleware) }>
    <BrowserRouter>
      <App/>
    </BrowserRouter>
  </Provider>, 
  'root' 
);

Rendering on Server Side

Option 1: Automation with CLI

Have your server file automatically generated by answering questions using our CLI.

To start up the CLI, do one of the following:

1. Type this command directly into your terminal
$ ./node_modules/.bin/he
2. Add a script to your package.json and run the script
"scripts": {
  "helium": "he",
},
$ npm run helium
3. Install globally and run the command
$ he

Image of CLI

Option 2: Do it Yourself

/* Include this in your server file 
(the file in which you initialize your 
express application) */

// import your root component
import App from './src/components/App.js';
const helium = require('helium.js');

// initialize your express application here

helium.init({
  // indicate the path to your main html file
  html: 'index.html',
  // specify the id to which your React application will be mounted on
  id: 'root',
  App,
});

// input api routes here

app.get('*', helium.serve);

(with Redux)

/* Include this in your server file 
(the file in which you initialize your 
express application) */

// import your root component and your reducer
import App from './src/components/App.js';
import reducer from './src/reducers';
const helium = require('helium.js');

// initialize your express application here

helium.init({
  // indicate the path to your main html file
  html: 'index.html',
  // specify the id to which your React application will be mounted on
  id: 'root',
  App,
  reducer,
});

// input API routes here

app.get('*', helium.serveRedux);

Running Your Application

If CLI was not used, add a script to your package.json to run your serverfile using babel-node.

"scripts": {
    "helium:start": "nodemon [server file name].js --exec babel-node --presets es2015",
},

Getting Production Ready

With the CLI:

The CLI would have automatically added threee scripts including helium:start, helium:build, helium:serve.

  1. Run helium:build to bundle your dynamically generated server file.
  2. Run helium:serve to serve your production ready file.

Without the CLI:

  1. Add an additional configuration to your webpack file to target the server file
{
  entry: path.join(__dirname, '[server file name].js'),
  target: 'node',
  output: {
    path: path.resolve(__dirname),
    filename: '[bundled server file name].js',
    libraryTarget: 'commonjs2',
  },
  module: {
    rules: [
      {
        test: /\.jsx?$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        query: {
          presets: ['env', 'react'],
        }
      },
    },
  },
}
  1. Add the following scripts to your package.json.
"helium:build": "webpack --config ./prod/helium.webpack.conf.js",
"helium:serve": "node ./prod/[server file name].prod.js"
  1. Follow the two steps above.

Performance Testing

You can also perform simple Critical Rendering Path testing after setting up server-side render with helium using the following:

1. Start your client-side application as usual
$ npm run start
2. Run lift -csr in a seperate terminal window and walk through the CLI interface
$ lift -csr
3. After evaluating your application, you will receive results for the client-side rendering instance in your terminal
$  "csr": {
    "webapi": {
      "DOMLoading": 34,
      "DOMContentLoaded": 75,
      "DOMComplete": 125
    }
  }
4. Repeat steps 1-3 running your server-side application instead
$ npm run helium:start
$ lift -ssr
$ "ssr": {
   "webapi": {
      "DOMLoading": 10,
      "DOMContentLoaded": 56,
      "DOMComplete": 112
    }
  }
5. After receiving results for both instances, run lift -diff.
$ lift -diff
# To run your application, type the following into your terminal
$ "diff": {
   "webapi": {
      "DOMLoading": 70.5882%,
      "DOMContentLoaded": 25.3333%,
      "DOMComplete": 6.25%
    } 
  }

Contributing

If you would like to contribute, submit a pull request and update the README.md with details of changes.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details

helium.js's People

Contributors

cli53 avatar juliemoon avatar shachyjr 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

Watchers

 avatar  avatar  avatar

helium.js's Issues

Command Line Questions

As a User, I want the option to run a command line to start the '-init' functional requesting preqs before building a server file for them.

CLI preliminary conditions

Provide user an option to select all the supportive libraries and API's that apply to their application

Require javascript expression

Webpack can't find the javascript expression module related to .

Related to the critical dependency warning.
Error message: "." cannot find module

refactor the files

everyone can to connect to the issue.
variable names
general refactoring
ES6 refactoring
remove comments
enable ESLints

Readme.md

Documentation for MVP. Detailing instructions for usage of our package

CLI prompt

Account for the paths of components that do not contain "./"

Throws error when requiring component if there is no "./" in the front of the path.

Hidden dist/public directories

Take into account for hidden dist/public directories because it's a common practice to add Web pack output bundles in .gitignore

serialization of store

Need to use module/tool to serialize store that gets injected into the html in the script tag under window.HE_CONFIG

React.js bug

  1. Create a fix for errors that I am running into
  2. Bundle React.js file

Add script to package.json

Automatically add script called "start-ssr" that will run server to user's package.json on npm install / cli interaction

user input file

make user input json file appear within our node modules directory, not within the root directory of the user's application

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

CLI npm script

CLI script to run npm start-test as well as optimize retrieving user data.

data.replace

Fix injecting react component string into html. RegEx is not working over multiple lines.

parsing index.js

We need to modify users index.js to comply with redux (might as well get the information we can while we're at it)

Editing Readme.md

  • Fixing errors found in readme.md to increase clarity
  • Adding a table of contents for ease of use
  • Changing structure of installation instructions to increase clarity (global v local installations)

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.