GithubHelp home page GithubHelp logo

crassa's Introduction

โœจ Create React App Server Side Application

๐Ÿ”‹ A CLI tool to create React + Server Side with one command

This project is a fork of Crana

๐Ÿ’ก To get up and running with an application with a node.js backend and a React frontend, just execute:

yarn global add crassa
crassa init <projectName> [projectFolder]

...and you are ready to go!

This will equip you with all important tools you're going to need to develop powerful applications, for example Live reaload for the server and the frontend out of the box. Webpack, Babel, ESLint, StyleLint, Nodemon etc. etc., all preconfigured out of the box, so that you can focus on the important stuff!

๐Ÿ’ป Now start developing!

yarn dev

This will fire up the backend and the frontend development server. Just edit files under src and see what happens!

โš ๏ธ Crassa is in early stage of development and may not meet all your requirements. That's why contributions of any kind are highly appreciated, as the best tools are built by communities!

Usage

โญ Create a new crana project.

crassa init <projectName> [projectFolderName]

๐Ÿ’ซ Concurrently starts the frontend and the backend in development mode.

yarn dev                                     

๐Ÿ“š See how many LOC you've already written.

yarn count                            

๐Ÿ” Executes eslint and styleling in autofix mode.

yarn lint

๐Ÿš— Starts the project for production with server side.

yarn start                                   

๐Ÿš™ Creates a production build for the frontend application.

yarn build                         

Project structure

The interesting files for you are all located in the src folder. The src folder has three subfolders:

  • src
  • server

As you can imagine, the src folder contains all files for the React frontend application and the server folder contains all files for the node.js backend.

Custom Template

You'll be able create custom template from github to generate your initial project: Github repository structure like:

.
โ””โ”€โ”€ template
    โ”œโ”€โ”€ nodemon.json
    โ”œโ”€โ”€ public
    โ”‚ย ย  โ”œโ”€โ”€ favicon.ico
    โ”‚ย ย  โ”œโ”€โ”€ index.html
    โ”‚ย ย  โ””โ”€โ”€ manifest.json
    โ”œโ”€โ”€ server
    โ”‚ย ย  โ”œโ”€โ”€ index.js
    โ”‚ย ย  โ””โ”€โ”€ v1
    โ”‚ย ย      โ”œโ”€โ”€ counter
    โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ index.js
    โ”‚ย ย      โ””โ”€โ”€ index.js
    โ””โ”€โ”€ src
        โ”œโ”€โ”€ App.js
        โ”œโ”€โ”€ App.test.js
        โ”œโ”€โ”€ components
        โ”‚ย ย  โ””โ”€โ”€ Common
        โ”‚ย ย      โ””โ”€โ”€ Loading.js
        โ”œโ”€โ”€ containers
        โ”‚ย ย  โ”œโ”€โ”€ Dashboard.js
        โ”‚ย ย  โ”œโ”€โ”€ DevTools.js
        โ”‚ย ย  โ”œโ”€โ”€ Root.dev.js
        โ”‚ย ย  โ”œโ”€โ”€ Root.js
        โ”‚ย ย  โ””โ”€โ”€ Root.prod.js
        โ”œโ”€โ”€ index.js
        โ”œโ”€โ”€ lib
        โ”‚ย ย  โ””โ”€โ”€ Request.js
        โ”œโ”€โ”€ reducers
        โ”‚ย ย  โ”œโ”€โ”€ base.js
        โ”‚ย ย  โ”œโ”€โ”€ counter.js
        โ”‚ย ย  โ””โ”€โ”€ index.js
        โ”œโ”€โ”€ registerServiceWorker.js
        โ”œโ”€โ”€ routes
        โ”‚ย ย  โ””โ”€โ”€ index.js
        โ”œโ”€โ”€ sagas
        โ”‚ย ย  โ”œโ”€โ”€ counter.js
        โ”‚ย ย  โ””โ”€โ”€ index.js
        โ”œโ”€โ”€ setupProxy.js
        โ””โ”€โ”€ store
            โ”œโ”€โ”€ configureStore.dev.js
            โ”œโ”€โ”€ configureStore.js
            โ””โ”€โ”€ configureStore.prod.js
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ .npmrc
โ””โ”€โ”€ package.json

Where package.json basically it must have name and displayName tag with {-- project-name --} and crassa with version tag {-- project-version --} like this:

{
    "name": "{-- project-name --}",
    ...
    "crassa": {
        "displayName": "{-- project-name --}",
        "aliases": {
            ...
        }
    },
    ...
    "dependencies": {
        "crassa":  "{-- project-version --}",
        ...
    },
    ...
}

You can put your git when crassa cli ask you to choose betwee custom or default template, the url mus to have this structure:

ghondar/counter-with-redux-ducks-and-sagas-template

Extensions

Here (server folder) you can extend universal middleware creating preLoadState.js file to dispatch action from server to load initial state into redux store.

Example: (/server/preLoadState.js)

import counterDuck from 'reducers/counter'

export default function(req, res, next) {
     // Get store from locals
     const { store } = res.locals
     // Dispatch a action to change initial state
     store.dispatch(counterDuck.creators.addCount())
     // Resave new store
     res.locals.store = store
     // Pass middlerware
     next()
}

Here (server folder) you can get the html created in universal.js to modify the initial load of DOM or wrapping your app src react project.

Example: (/server/universal.js)

import { renderToString } from 'react-dom/server'

export const setRenderUniversal = (htmlData, app, store) => {
    // store => access to store ( redux )

    const renderString = renderToString(app) // wrapping optional

    const materialStyle = `
      <style id='css-server-side' type="text/css">
        html { margin:0px; padding:0px }
      </style>
    `

  return {
    prevHtml: html.replace('<head>', `<head>${materialStyle}`),
    renderString // optional
  }
}

We handle initial configuration here adding babel plugins (transform-imports, loadable-components and transform-react-remove-prop-types) and webpack alias (basic alias from package.json) but you can extend this initial configuration adding to your root project config-overrides.js file.

Example: (/config-overrides.js)

const { override, addWebpackAlias, addBundleVisualizer } = require('customize-cra')

module.exports = override(
	process.env.BUNDLE_VISUALIZE == 1 && addBundleVisualizer()
)

Technologies

As soon as you bootstrapped a new project, you have an application running with:

Under the hood it uses Webpack, Babel, ESLint with a few other plugins enabling a powerful development workflow.

Known constraints/issues

Windows Linux Subsystem

If you're using Windows Linux Subsystem, eslint will not immediatly work. You need to edit the path under .vscode/settings.json. Replace C:/mnt/c with C: and it should work.

Contributing

Have a look at CONTRIBUTING.md

Code of conduct

Have a look at CODE_OF_CONDUCT.md

crassa's People

Contributors

ghondar avatar grovertb avatar

Watchers

 avatar  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.