6 ms·
React Static Site
- colinramsay 11y agoFacebook does this with the React Native website I believe: https://github.com/facebook/react-native/tree/master/website/server https://github.com/facebook/react-native/tree/master/website...
- mambodog 11y agoThe React DnD docs/examples site is rendered in a similar manner: https://github.com/gaearon/react-dnd/blob/master/scripts/buildSiteIndexPages.sh https://github.com/gaearon/react-dnd/blob/master/scripts/bui...
- onion2k 11y agoI don’t feel the need to join the WordPress cult Blogging 101: If you write petty, snarky comments about millions of other developers, people will focus on those rather than the content of your post.
- vkjv 11y agoWhat is the argument for going completely static? Static as in not using React on the client, not as in static files. It seems (to me), that it would be useful--in addition to the static html--load React on the client and from that point navigate with push state and small static (JSON?) files. It might perform better if your blog has a lot more interactivity. Although, here I can definitely see that as being fluff.
- jacquesm 11y agoSpeed, simplicity, security.
- sergiotapia 11y agoSynergy.
- dugmartin 11y agoI played around with building something similar. The problem becomes that you have to send down twice the amount of data for the page - the statically rendered html generated from your data and then the data itself so that when the React components mount their props/state match the statically generated html.
- bryanlarsen 11y agoThe easy fix for that is to send the data asynchronously in a separate request. It takes a little longer for the page to go "live", but the static part is functional quicker. A harder fix is to walk the static DOM to inflate your store. It shouldn't be too hard since you can add hints to the DOM to guide your parser.
- adregan 11y agoA few of the flux implementations have the concept of "rehydrating" state (serializing and deserializing the stores), which does allow the client side to reuse the data and keeps the component from refetching the data. A useful pattern I discovered was fetching just what is necessary to render the page on the server. Then pass the state to the window object through a script tag and recover the data on the client side and rehydrate. Any additional data (or potentially slow returning), I fetch client side via `componentDidMount` [0] which isn't called on the server. This way, I can get a loading screen up as quickly as possible with a few elements custom to the user. I should note that even thought the flux library I was using, flummox [1], works great for this, I can't recommend it as in the month and a half I was working on my project they've decided to quit and recommend a different library, so I'm not sure what to recommend now (the frustration I feel over this quick turnaround is an entirely separate topic, though). 0: https://facebook.github.io/react/docs/component-specs.html#mounting-componentdidmount https://facebook.github.io/react/docs/component-specs.html#m... 1: http://acdlite.github.io/flummox http://acdlite.github.io/flummox 2: https://github.com/acdlite/flummox#40-will-likely-be-the-last-major-release-use-redux-instead-its-really-great https://github.com/acdlite/flummox#40-will-likely-be-the-las...
- betenoire 11y ago
- asolove 11y agoI am using static-site-generator-webpack-plugin [0] on a client project now and it has been fantastic. I have one json file full of all the data of the site and then a bunch of components that render it in various ways. I've got translations in several languages plus the components can use React-Intl to get text, dates, etc. in the right format for the locale. The experience has been fantastic compared to other static site generators (very limited control over display of content) or CMSes (too indirect for what is basically simple logic, especially around internationalization). It was a bit fiddly getting everything set up so that React, React Router, React Intl, and Static Site Generator all played nicely together. But after about a day of banging my head on that, it's just worked ever since and been a dream. If I could ask for one improvement: right now the build first runs the code through Babel and then runs that through WebPack. Problem is, if parts of the Babel build fail, there's no error reporting, and instead I get a WebPack-stage error about some file not being available. I then have to manually run the file through Babel to see that there's a simple syntax error. [0] https://github.com/markdalgleish/static-site-generator-webpack-plugin https://github.com/markdalgleish/static-site-generator-webpa...
- TN1ck 11y agoYou can use babel-eslint [0] and the eslint-loader [1] to catch all errors babel might have. [0] https://github.com/babel/babel-eslint https://github.com/babel/babel-eslint [1] https://github.com/MoOx/eslint-loader https://github.com/MoOx/eslint-loader
- asolove 11y agoAwesome, thanks!
- nkohari 11y agoI'm using pretty much the same setup, and the only trouble I have is that simple React exceptions can cause webpack-dev-server to terminate. It's not the end of the world, just kind of annoying to have to restart the dev server if I misspelled a variable! I'm not sure if this is the same problem you've encountered, but if you find a solution I'm definitely interested. :)
- digitalzombie 11y agoI use Octopress, it's basically a wrapper around Jekyll. http://octopress.org/ http://octopress.org/ You just have to memorize a few command to publish stuff. Also of course, know Markdown.
- danesparza 11y agoI believe you have to install Ruby as well -- don't you?
- digitalzombie 11y agoI'm not sure if you're joking but... it's a given. Likewise with PHP and wordpress or Node.js and Ghost.
- danesparza 11y agoIt's not a given, and I wasn't joking. I've used Jeykl and Octopress and a few others. I dislike having to install random libraries just to get simple blog to render properly. Go-lang built tools (like the free and excellent Hugo - https://gohugo.io/ https://gohugo.io/) are single binaries. Just get the one that works on your platform.
- jlu 11y agoAlso have a look at metalsmith-react: https://github.com/coodoo/metalsmith-reactjs https://github.com/coodoo/metalsmith-reactjs
- TeeWEE 11y agoI like the idea of React. However, Mixing HTML in your javascript is a very bad thing. You are mixing presentation with logic, and i always try to prevent that. Keep your logic away from your templates. I think its doable with react, but most people dont do it... Can somebody explain me why? + return ( + <html> + <head> + <title>{this.props.title}</title> + </head> + <body> + {this.props.children} + {script} + </body> + </html> + ); https://github.com/jlongster/blog/blob/master/src/components/header.js https://github.com/jlongster/blog/blob/master/src/components...
- JuanSoto 11y agoHere's a good answer to your question: https://www.reddit.com/r/javascript/comments/2uvz0x/whats_so_great_about_reactjs/coc6bod https://www.reddit.com/r/javascript/comments/2uvz0x/whats_so...
- bryanlarsen 11y agoReact is a view layer, so a good React component is all presentation and doesn't contain any business logic. The only logic in a React component is presentation logic, which belongs together with your presentation structure and your presentation style, IMO.
- TeeWEE 11y agoI like this answer, however, its still not sufficient. Because you dont want to mix the "structure" of your UI with the behaviour of it. But in very dynamic apps behaviour = structure. So in that case React makes sense. However, i dove into web components with Polymer, and it seems that this is the "official" direction of components in the future web... It also doesnt try to mix HTML with JavaScript. In fact in the future there will be more langauges than javascript since there will be a bytecode for the browser. Having your app written in React poses a real problem when you want to switch your logic to a different programming language. So isnt the Web Components solution much better? It seems that React and Web Components can be combined: https://github.com/Wildhoney/Maple.js https://github.com/Wildhoney/Maple.js
- zastavka 11y agoThis is a pretty neat approach to building a static site, and it reminds me that a couple months ago I was experimenting with building a static site generator in Clojure. Which makes me think – is there any reason something like this couldn't be done with Clojurescript and Reagent? I've been itching to try out both of those but haven't come up with a good project for it. The hard part might be routing, since there doesn't seem to be a robust solution for doing that in Reagent yet. I found https://github.com/ghedamat/reagent-react-router https://github.com/ghedamat/reagent-react-router but it hasn't been updated in months and the author calls it "very very alpha."
- enoch_r 11y agoI've been using reagent with re-frame[1]. Routing just uses goog.events and goog.history to listen for navigation events, secretary[1] to define routes, which update the state rendered by your components. The code is here: https://github.com/Day8/re-frame-template/blob/master/src/leiningen/new/re_frame/src/cljs/routes.cljs https://github.com/Day8/re-frame-template/blob/master/src/le... [1] https://github.com/Day8/re-frame https://github.com/Day8/re-frame and https://github.com/Day8/re-frame-template https://github.com/Day8/re-frame-template You'll have to do `lein new re-frame <project> +routes` to pull in the routing template. [2] https://github.com/gf3/secretary https://github.com/gf3/secretary
- zastavka 11y agoThanks for this! re-frame's probably little heavyweight for what I'd want to do, but secretary looks rad, so at the very least I'll look into that.
- alinspired 11y agohttp://docpad.org/ http://docpad.org/ seems to be an alternative. It worked great as a static blog generator with multitude of npm plugings and tools to choose