Giter Site home page Giter Site logo

a382695908 / react-webpack-server-side-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from webpack/react-webpack-server-side-example

0.0 1.0 0.0 152 KB

Example of an react application with webpack including server-side rendering.

CSS 2.31% JavaScript 97.69%

react-webpack-server-side-example's Introduction

react-webpack-server-side-example

Example of an react application with webpack including server-side rendering.

This is not for the normal user. This example is meant as inspiration to develop an framework that can do server-side rendering of react with webpack. You shouldn't use the code, only the idea.

Overview

webpack compile with two separate configurations: One for the browser bundle and one for the react application for server-side rendering. The server-side bundle can be required in other node.js code to build the pre-rendered HTML.

Features

  • Same react code (app/Application.js) run on server and on client
  • In both cases the code is compiled with webpack
    • Supports loaders i. e. file-loader for assets
  • The server-side compilation collects styles and include them in the pre-rendered HTML
    • This avoids FOUC of the pre-rendered HTML
  • browser build includes a hash in url for caching

Usage

npm start

Run the 2 steps:

  1. Compile the browser bundle and the server-side bundle. It also stores stats from the browser bundle as json file.
  2. Starts a server. The server requires the server-side bundle, which generates HTML for every request. It also reads the filename of the browser bundle to insert the <script>-tag.

Production

npm run production

This compiles production versions for the browser and server-side bundles. It also minimizes javascript and css.

License

None. Don't copy the code, only use the idea.

Copyright 2014 Tobias Koppers

react-webpack-server-side-example's People

Contributors

sokra avatar

Watchers

 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.