Giter Club home page Giter Club logo

kickstart-meteor-react-flowrouter-ssr-codesplit's Introduction

Intro

Skeleton project for Meteor with React, Redux, Webpack, FlowRouter, Server side rendering (SSR) and code splitting! It's the skeleton project I wish I'd had when starting a serious Meteor project. It aims at providing all the structure and boilerplate for a modern web app.

If you like it, give it some stars :)

Goal

Provide an excellent starting point for an ambitious Meteor app. There's probably some overkills if you're doing a hackathon project.

How to help

I'd love to get contributions on what you wish you'd knew when you got seriously started. There're are a few things that come in mind: more tests, deployement scripts, mantra, etc. But any idea/feedback/PR is welcomed!

Sharing experience about the key technologies:

Meteor

Meteor is a fullstack javascript framework.

It's great at:

  • managing data: everything is reactive and it's taken care of for you; client and server data logic can be shared.
  • optimistic UI: the client is able to anticipate server responses and instantly updates the UI (-> great UX)
  • npm: anything that is in npm, you can get it within Meteor.
  • lot of time saved when getting started:
    • build for production is taken care off. It refreshes clients live.
    • isomorphism: you can share code between client and server.
    • plenty of awesome community packages. I could not emphasize it enough.

It is not great at:

  • build time: client and server rebuilds are not super fast, and can be very long. It's not easy nor transparent to use other build build tools you might be used to or want to use, because they do a better job at what they've been build for (like webpack).
  • being opiniated: it wraps your entire stack, but doesn't tell you which rendering frameworks, or which databases type to use. While that sounds awesome it also splits the effort of the community and Meteor team.

React

React, from Facebook, is a front end framework that manages app logic and UI rendering.

It's great because:

  • the design pattern (UI is a function of state) is very clear. It makes your client logic beautiful.
  • rendering is very smart and efficient.
  • it has two parts: the logic and the UI. The UI depends on the platform (Web, iOS, Android) but the logic remains the same. Learn once, write anywhere.
  • it can be used for native apps with React Native.
  • documentation is awesome
  • it has a big community behind it

It's not great because:

  • it's one more thing to learn
  • it represents a decent amounts of kb of code to bundle with the app

Redux

Redux is an implementation of Flux, which is a pattern to handle app logic.

It's great because:

  • it makes things super clean and help your codebase to scale.
  • it's very well documented.

It's not great because:

  • it feels like boilerplate

Webpack

Webpack is a build process for web apps.

It's great because:

  • it's super customisable, and can do a loooot.
  • it refreshes client code almost instantly. That will improve development by a lot (there're other ways to do just that)
  • it is becoming the default in the node community

It's not great because:

  • it's one more thing to learn
  • startup build takes a while
  • it doesn't play very well with Meteor, because Meteor is not super complient with node standards (but getting there) and has different build standards.

FlowRouter

FlowRouter is a great router for Meteor. It can handle server side rendering.

Code splitting

Code splitting is the idea of having a client app that loads its code by chunks when needed instead of all at once.

Storybook

Storybook is a great way to see your UI components in isolation, to make sure all looks good and to quickly work on a single component.

Tests

Tests.. well you should write them! Here I show how to write unit tests on UI components, but there's much more to do.

Running

Installation

git clone https://github.com/gsabran/kickstart-meteor-react-flowrouter-SSR-codeSplit.git
cd kickstart-meteor-react-flowrouter-SSR-codeSplit
npm install

Run

  • Meteor
meteor
  • Storybook
npm run storybook
  • tests / lint
npm run testonly
npm run lint
npm run test # both test and lint

Understand

  • play around with the app at http://localhost:3000 to see what it does. It's basic.
  • open ./package.json and follow the comments

Production

Use mupx

Things to be aware of

  • SSR prevents Hot Module Reload (HMR) since the server compile client code and therefore rebuild everytime you change it. You probably want to disable SSR in development. To do that, change this line
  • code splitting only works on the client so you will see code like
  // src/task/router.jsx
  if (Meteor.isServer) {
    const TaskContainer = require('./containers/Task.jsx');
    mountComponent(TaskContainer);
  } else {
    require.ensure([], function(require) {
      const TaskContainer = require('./containers/Task.jsx');
      mountComponent(TaskContainer);
    });
  }

that loads code differently in the server and the client. This boilerplate is a bit annoying :)

  • style doesn't get added by default on the server (when doing SSR) so:
    • by default SSR would produce a code with missing style and the page would be ugly until the client side code runs
    • to avoid that:
      • on the server, the style is added in the head as raw text with a utility function that is part of the boilerplate
      • style gets loaded differently on the client and the server:
        // src/task/components/Task.jsx
        const style = Meteor.isClient ?
          require('../css/Task.import.css') :
          require('!css!../css/Task.import.css');

kickstart-meteor-react-flowrouter-ssr-codesplit's People

Contributors

gsabran 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

Watchers

 avatar  avatar  avatar  avatar

kickstart-meteor-react-flowrouter-ssr-codesplit's Issues

SSR not working with 1.4.2

Hi,
thank you for this kickstart project till version 1.3.4.4 of Meteor this works very well.
I recently tried the version 1.4.2 and there I have problems getting SSR to work in this project.

Do you have an idea what could be the issue here?

I do have every package up-to-date for version 1.3.4.4 but when upgrading the result is (with deactivating javascript) that there is only a white page showing up in the browser.

Thank you!

Branch with update to latest meteor release omitting SSR (for now)

I tried to update this boilerplate to the latest meteor release but get stuck with an error on meteor start in the linking stage:

/home/xxx/.meteor/packages/meteor-tool/.1.4.3_1.raltwe++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/fibers/future.js:280
throw(ex);
^

SyntaxError: Unexpected end of input
at Object.parse (native)
at /tools/fs/optimistic.js:204:17
at wrap.makeCacheKey._len2 (/tools/fs/optimistic.js:22:15)
at Entry._reallyRecompute (/home/quest/.meteor/packages/meteor-tool/.1.4.3_1.raltwe++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/optimism/lib/entry.js:215:26)
[ ... ]

Because I can abandon SSR in my project I already switched from flow-router-ssr to flow-router.
That didn't change anything on this error.

In meantime until there is a new flow-router maintainer or we get another ssr routing solution from MDG or the community, could you create a branch updated to the latest meteor release working without SSR?

That would help me a lot.
I already worked with react and komposer on several projects, but I am not really familliar with redux and webpack.
Unfortunatly I need subresource integrity in a current project which I plan to solve using a webpack plugin. To do that I of course need a running meteor/webpack project first :-/
(Will of course release my webpack-sri package if it works ;) )

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.