Giter VIP home page Giter VIP logo

webpack2-react-hmr-ssr-express-stylus's Introduction

Tech

  • Webpack 2
  • Express 4 + webpack dev server hot reload
  • React 15.4 (+ some babel optimizations including transform-runtime)
  • React hot module reload (including server-side thanks to decache in dev mode)
  • Server-side rendering (thanks to babel-register)
  • webpack manifest for production builds hashing
  • Stylus + autoprefixer

Webpack in webpack.config.js uses separate babel config with disabled modules, so webpack can handle natively all import, exports to enable Tree Shaking for minimal bundle size.

Also there is no need to write import React from 'react' in every *.jsx file thanks to babel's react-require plugin.

How

For production build (node start slow first time to compile JSX):

yarn
npm run build
NODE_ENV=production node src/server/server.js

For development (HMR and staff):

npm run dev

webpack2-react-hmr-ssr-express-stylus's People

Watchers

Dimitry avatar James Cloos avatar Jesse Feng avatar

webpack2-react-hmr-ssr-express-stylus's Issues

Add security middlewares

Like:

const helmet = require('helmet'),
    uuid = require('uuid'),
    csurf = require('csurf'),
    config = require('./config'),
    csp = {...};

// for webpack HMR
if (config.isDevelopment) {
    csp.scriptSrc.push('\'unsafe-inline\'');
    csp.scriptSrc.push('\'unsafe-eval\'');
}

module.exports = {
    nonce: (req, res, next) => {
        res.locals.nonce = uuid.v4();
        next();
    },
    helmet: helmet({
        contentSecurityPolicy: {
            directives: csp
        }
    }),
    csrfAddToken: (req, res, next) => {
        res.locals.csrfToken = req.csrfToken();
        next();
    },
    csrf: csurf({
        cookie: true
    })
};

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.