From 182b2a980fe40aa2fffee7939d453ef5905b501e Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Tue, 22 Dec 2015 14:00:22 +0100 Subject: [PATCH] reduced initial download size --- webapp/app.jsx | 238 +++++++++++++++++++++---------------- webapp/components/icon.jsx | 1 - webapp/index.html | 14 ++- webpack.config.js | 2 +- 4 files changed, 146 insertions(+), 109 deletions(-) diff --git a/webapp/app.jsx b/webapp/app.jsx index e4a7389..9310242 100644 --- a/webapp/app.jsx +++ b/webapp/app.jsx @@ -1,111 +1,143 @@ -var React = require('react') -var ReactDOM = require('react-dom') -var Router = require('react-router').Router -var Route = require('react-router').Route -var IndexRoute = require('react-router').IndexRoute - // Load CSS + require('normalize.css') require('skeleton.css') -require('style.css') require('raleway.css') -// Load Components - -var BoardsWrapper = require('boardsapiwrapper.js') -var boards = new BoardsWrapper() -var Icon = require('icon.jsx') - -// Load pages - -var Navbar = require('navbar.jsx')(boards) -var Users = require('users.jsx')(boards) -var Settings = require('settings.jsx')(boards) -var Profile = require('profile.jsx')(boards) -var Board = require('board.jsx')(boards) -var PostPage = require('postpage.jsx')(boards) -var CommentPage = require('commentpage.jsx')(boards) -var ProfileEditor = require('profile-editor.jsx')(boards) -var BoardEditor = require('board-editor.jsx')(boards) -var PostEditor = require('post-editor.jsx')(boards) -var Status = require('status.jsx')(boards) - -// Define Main Components - -var Container = React.createClass({ - render () { - return (
{this.props.children}
) - } -}) - -var App = React.createClass({ - render () { - return (
{this.props.children}
) - } -}) - -// Static pages - -var Static = React.createClass({ - html () { - return { __html: this.props.content } - }, - render () { - if (this.props.content) { - return
- } else { - return - } - } -}) - -var Homepage = React.createClass({ - render () { - return - } -}) - -var NotFound = React.createClass({ - render () { - return (
-

-

Sorry, there's nothing here!

-
) - } -}) - // Start -ReactDOM.render( - - - - - - - - - - - - - +document.getElementById('root').innerHTML = ` +
+

Loading

+

Gathering components

+
+` + +require.ensure('react', _ => { + var React = require('react') + // Load CSS + require('style.css') + require('font-awesome.min.css') + // Load Components + var BoardsWrapper = require('boardsapiwrapper.js') + var boards = new BoardsWrapper() + var Icon = require('icon.jsx') + // Load pages + var Navbar = require('navbar.jsx')(boards) + var Users = require('users.jsx')(boards) + var Settings = require('settings.jsx')(boards) + var Profile = require('profile.jsx')(boards) + var Board = require('board.jsx')(boards) + var PostPage = require('postpage.jsx')(boards) + var CommentPage = require('commentpage.jsx')(boards) + var ProfileEditor = require('profile-editor.jsx')(boards) + var BoardEditor = require('board-editor.jsx')(boards) + var PostEditor = require('post-editor.jsx')(boards) + var Status = require('status.jsx')(boards) + + // Define Main Components + + var Container = React.createClass({ + render () { + return (
{this.props.children}
) + } + }) + + var App = React.createClass({ + render () { + return (
{this.props.children}
) + } + }) + + // Static pages + + var Static = React.createClass({ + html () { + return { __html: this.props.content } + }, + render () { + if (this.props.content) { + return
+ } else { + return + } + } + }) + + var Homepage = React.createClass({ + render () { + return + } + }) + + var NotFound = React.createClass({ + render () { + return (
+

+

Sorry, there's nothing here!

+
) + } + }) + + var RootComponent = React.createClass({ + getInitialState () { + return {} + }, + componentDidMount () { + require.ensure(['react-router'], _ => { + this.setState(require('react-router')) + }) + }, + render () { + if (this.state.Router) { + var Router = this.state.Router + var IndexRoute = this.state.IndexRoute + var Route = this.state.Route + return + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - , document.getElementById('root') -) + + } else { + return
+
+ +

Downloading Components

+
+
+ } + } + }) + require.ensure('react-dom', _ => { + var ReactDOM = require('react-dom') + ReactDOM.render( + , document.getElementById('root') + ) + }) +}) diff --git a/webapp/components/icon.jsx b/webapp/components/icon.jsx index b5f8c88..d53de80 100644 --- a/webapp/components/icon.jsx +++ b/webapp/components/icon.jsx @@ -1,5 +1,4 @@ var React = require('react') -require('font-awesome.min.css') module.exports = React.createClass({ class: function () { diff --git a/webapp/index.html b/webapp/index.html index ed8180d..8a4fb6e 100644 --- a/webapp/index.html +++ b/webapp/index.html @@ -2,22 +2,28 @@ - + {%= o.htmlWebpackPlugin.options.title %} -