All Projects → lostpebble → Koa Mobx React Starter

lostpebble / Koa Mobx React Starter

Licence: unlicense
A straightforward starter for Node javascript web projects. Using Koa, MobX and ReactJS (with universal / isomorphic server rendering)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Koa Mobx React Starter

Award
⚙基于react的服务端渲染框架
Stars: ✭ 91 (-10.78%)
Mutual labels:  webpack, babel, koa, react-router
React Isomorphic Boilerplate
🌟 An universal React isomorphic boilerplate for building server-side render web app.
Stars: ✭ 653 (+540.2%)
Mutual labels:  webpack, babel, koa2
Xiaoduyu.com
🐟小度鱼 - 年轻人的交流社区 https://www.xiaoduyu.com
Stars: ✭ 549 (+438.24%)
Mutual labels:  webpack, babel, react-router
React Article Bucket
总结,积累,分享,传播JavaScript各模块核心知识点文章全集,欢迎star,issue(勿fork,内容可能随时修改)。webpack核心内容部分请查看专栏: https://github.com/liangklfangl/webpack-core-usage
Stars: ✭ 750 (+635.29%)
Mutual labels:  webpack, babel, react-router
Blog
Front-end tech thoughts and share-ppt
Stars: ✭ 288 (+182.35%)
Mutual labels:  webpack, babel, koa2
Pwa
An opinionated progressive web app boilerplate
Stars: ✭ 353 (+246.08%)
Mutual labels:  webpack, babel, react-router
React Ssr Setup
React Starter Project with Webpack 4, Babel 7, TypeScript, CSS Modules, Server Side Rendering, i18n and some more niceties
Stars: ✭ 678 (+564.71%)
Mutual labels:  webpack, babel, react-router
Koa Webpack Middleware
webpack dev&hot middleware for koa2
Stars: ✭ 215 (+110.78%)
Mutual labels:  webpack, koa, koa2
Skyvow.github.io
🐶 My resume - 个人简历
Stars: ✭ 27 (-73.53%)
Mutual labels:  webpack, babel, react-router
Express React Boilerplate
🚀🚀🚀 This is a tool that helps programmers create Express & React projects easily base on react-cool-starter.
Stars: ✭ 32 (-68.63%)
Mutual labels:  webpack, babel, react-router
Webpack Core Usage
webpack2完整系列课程,欢迎阅读。同时欢迎移步我的react全家桶文章全集: https://github.com/liangklfangl/react-article-bucket
Stars: ✭ 94 (-7.84%)
Mutual labels:  webpack, babel, react-router
react-pits
React 中的坑
Stars: ✭ 29 (-71.57%)
Mutual labels:  babel, react-router, mobx
React
Extremely simple boilerplate, easiest you can find, for React application including all the necessary tools: Flow | React 16 | redux | babel 6 | webpack 3 | css-modules | jest | enzyme | express + optional: sass/scss
Stars: ✭ 244 (+139.22%)
Mutual labels:  webpack, babel, react-router
React Lego
React-lego : incrementally add more cool stuff to your react app
Stars: ✭ 417 (+308.82%)
Mutual labels:  webpack, koa, react-router
React Course
Code for ui.dev's "React" course
Stars: ✭ 2,457 (+2308.82%)
Mutual labels:  webpack, babel, react-router
React Mobx Ts Antd
A simple empty project build with react、react-router、mobx、antd in typescript.
Stars: ✭ 53 (-48.04%)
Mutual labels:  webpack, react-router, mobx
React Redux Universal Boilerplate
An Universal ReactJS/Redux Boilerplate
Stars: ✭ 165 (+61.76%)
Mutual labels:  webpack, babel, react-router
Koa Web Kit
🚀A Modern, Production-Ready, and Full-Stack Node Web Framework with React
Stars: ✭ 199 (+95.1%)
Mutual labels:  webpack, babel, koa2
Ghchat
📱A chat application for GitHub. React + PWA + Node(koa2) + Typescripts + Mysql + Socket.io
Stars: ✭ 791 (+675.49%)
Mutual labels:  webpack, koa2, react-router
Budgeting
Budgeting - React + Redux + Webpack (tree shaking) Sample App
Stars: ✭ 971 (+851.96%)
Mutual labels:  webpack, babel, react-router

koa-mobx-react-starter

the Jackson Pollock of github logos

Along with aiming to use the bleeding-edge of JavaScript (within reason- and all thanks to Babel), this repository represents a choice of frameworks and libraries I think work well together for an enjoyable NodeJS and frontend coding experience.

New ☀️ - React-Router
New ☀️ - Marko

A short rundown of the various technologies:

Server

  • Koa - A Node server framework with an eye on the future, using the async-await syntax. Server code compiled back to a widely adopted standard of JavaScript using Babel.
  • Marko - Fast HTML rendering engine, into which we slot in our React-generated HTML

Crossover

  • MobX - Awesome state management library, makes it so easy I feel like I'm cheating somehow. State stores initialized on the server, altered by some actions depending on request, and then passed over to the client to continue its state-altering journey.
  • ReactJS - Build views on the server according to state and then inject functionality into those already built views on the client, and continue calling MobX actions and re-rendering accordingly
  • React-Router - A routing solution for ReactJS. Works great with server-side rendering too, catching all possible routes we may want to render.

Client

  • Javascript compiled with Webpack - A bundler that reads your entry JavaScript and various other files and creates a distribution build of them (using various options and plugins) for efficient client-side delivery
  • Client Javascript mostly involves more React and MobX goodness for great interaction

Folder and Module Structure

Folder What's in it
/client /react
  • Regular React components, main App component and whatever else makes up the layout.
  • /svg - SVG React components. Placed directly in the code as if they were normal functional React components. Much easier to incorporate into layouts. They're usually very small in size (1-3kb) so it's not a data hog and means they load instantly with SSR too.
  • /routes - The React-Router defined routes for our app
/styles
  • A bunch of organised .scss, Sass style modules. The main one, entry.scss, is included in our entry.js so webpack knows it's part of our client bundle (and hot reloading works because it becomes part of the "hot" bundle)
  • By using Webpack, when we compile for production, these styles are automatically extracted into a seperate styles.css file that we can include in the head of our html.
/crossover /api
  • API functions (returning promises) that work on both client and server side using isomorphic-fetch
  • These APIs are most likely only going to be called from MobX stores, since all our state is managed by them and it makes it very easy to reason about what we're doing if there are only a few endpoint actions (functions) we have to call on both client and server.
/constants
  • Pretty self explanatory, just constants to be used throughout the app. For now it's just different types of tabs. This allows us to think about certain parts of the UI as one, constant thing and therefore we can create things like language dictionaries that can be access according to a language constant and the UI constant but the components remain exactly the same.
  • For now there are no constants, as before there used to be some to keep track of tabs- that is managed by the different routes in React-Router now. BUT constants are still a very important part of an app's ecosystem in order to maintain consistency between things. It is left here as an empty folder to be expanded upon.
/mobx
  • /stores - All the MobX stores in seperate modules, which are basically just classes with @decorators to keep things neat. some of them access API files from above.
  • allStores.js - The only part of the code that feels too static too me, but required for the next step. We just bundle all the modules from the folder above into a single exported object. This enables what happens in the next file.
  • store-utils.js - Creating and hydrating stores (for now the only utils). It requires that we remember to put our stores in the imported allStores.js above so they are included in the processes. Used on the server side first to create new stores (which are then used normally before the request returns), and then hydrated on the client side (taking the state that came from the server and mirroring it exactly on the client side MobX stores).
entry.js
  • The most important crossover file. It has a baseReact() function which returns our main React app (components) that we want to mount onto our page. This is so there is a single source of truth for both server and client. It is also the entry file for our client javascript, so it takes control of getting the MobX state from the server-generated page and injecting that into our client MobX stores before rendering the exact same React components the server just spat out. But it is not actually rendered again, because React is smart, React simply sees it's all the same so doesn't re-render the dom but simply makes what's already there dynamic and functional.
/images Self explanatory
/server babel-server.js
  • The entry point for our server. It makes use of babel-register which insures that all further files required by our server will be transpiled to ES5 javascript code (understood by Node).
server.js
  • Our actual server file. It's a basic Koa server, makes use of some base middleware imported from the /middleware folder and a router from /router
  • Take a look inside /middleware/crossoverMiddleware.js to see how MobX state is first created, and then used to render our React at the end of a request.
  • The amazing part about Koa is its use of async functions and using the await key word for request/response streams. Makes things much easier to reason about, especially with our MobX stores also returning async / await functions which themselves can be await'ed. Take a look inside the router file to see it in action.
  • Within our server we make use of Pug as the view engine. We also serve files in the /static directory thanks to some middleware which you can find in the /middleware/basicMiddleware.js file.

Get Going:

For starters:

npm install

Or, even better (if you are using yarn):

yarn install

Then

To start the development server (which is what you want most of the time)

npm run dev

To start the production server is the usual npm start, but the code has to be built first, so:

npm run build
npm start

Or for quick production testing npm run build-start

Before deployment to a production server, your code should always be built first- so that the default npm start can be used to spin up quickly.

Some Extra Configuration Information

I'm using the babel-register module which is required before any other server code and automatically converts any further requires / imports to ES5 javascript. This is for development purposes only (npm run dev ) - as recommended.

The server code (and the React code which is used on the server) is then built into the /built folder for production use ( npm start )

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