All Projects → yusinto → universal-hot-reload

yusinto / universal-hot-reload

Licence: MIT license
Hot reload client and server webpack bundles for the ultimate development experience

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to universal-hot-reload

arelo
a simple auto reload (live reload) utility
Stars: ✭ 54 (-31.65%)
Mutual labels:  livereload, live-reload, reload
react-hot-loader-starter-kit
react 16, redux 5, react router 4, universal, webpack 3
Stars: ✭ 41 (-48.1%)
Mutual labels:  universal, hot-reload, hot-module-replacement
hot-reload
Hot reload development for Go
Stars: ✭ 72 (-8.86%)
Mutual labels:  livereload, hot-reload
Jet Live
c++ hot code reload for linux and macos
Stars: ✭ 283 (+258.23%)
Mutual labels:  livereload, hot-reload
Boot Figreload
Boot task providing live-reload using Fighweel client
Stars: ✭ 50 (-36.71%)
Mutual labels:  livereload, hot-reload
vue-webpack
Boilerplate for vue single file components with webpack
Stars: ✭ 24 (-69.62%)
Mutual labels:  webpack-dev-server, hot-reload
hotbuild
a cross platform hot compilation tool for golang
Stars: ✭ 181 (+129.11%)
Mutual labels:  live-reload, hot-reload
electron-angular-ngrx
An Angular (6x) Electron seed featuring @angular/cli, @ngrx/platform, and Typescript. Complete with HMR workflow
Stars: ✭ 39 (-50.63%)
Mutual labels:  livereload, hot-module-replacement
Flexlib
FlexLib是一个基于flexbox模型,使用xml文件进行界面布局的框架,融合了web快速布局的能力,让iOS界面开发像写网页一样简单快速
Stars: ✭ 1,569 (+1886.08%)
Mutual labels:  livereload, hot-reload
Vscode Live Server
Launch a development local Server with live reload feature for static & dynamic pages.
Stars: ✭ 3,275 (+4045.57%)
Mutual labels:  livereload, live-reload
react-ssr-spa
Server side rendered single page app using reactjs official libraries.
Stars: ✭ 30 (-62.03%)
Mutual labels:  universal, hot-reload
react-spa-template
This is a sample template for single page applications built using React + Router to work with webpack dev server
Stars: ✭ 19 (-75.95%)
Mutual labels:  webpack-dev-server, hot-module-replacement
active reloader rb
Rails gem that reloads browser as soon as any file is changed
Stars: ✭ 11 (-86.08%)
Mutual labels:  hot-reload, reload
live-reload-vanilla-website-template
Template to build a website without a front-end framework, including transpilation of ES6+ JavaScript and Sass support
Stars: ✭ 47 (-40.51%)
Mutual labels:  livereload, live-reload
minimal-hapi-react-webpack
Minimal Hapi + React + Webpack + HMR (hot module reloading) Sandbox
Stars: ✭ 55 (-30.38%)
Mutual labels:  hot-reload, hot-module-replacement
easywebpack-react
React Webpack Building Solution, Support React Server Side Render (SSR), Client Side Render (CSR) Building
Stars: ✭ 14 (-82.28%)
Mutual labels:  hot-reload, hot-module-replacement
lets-hotfix
Dynamic class reloading for java。Java代码热更新,支持本地、远程
Stars: ✭ 124 (+56.96%)
Mutual labels:  reload, reloading
vue-hot-reload-loader
Enable hot module replacement (HMR) on your Vue components
Stars: ✭ 20 (-74.68%)
Mutual labels:  hot-reload, hot-module-replacement
Boot Reload
Boot task providing live-reload of browser css, images, etc.
Stars: ✭ 90 (+13.92%)
Mutual labels:  livereload, hot-reload
Reactql
Universal React+GraphQL starter kit: React 16, Apollo 2, MobX, Emotion, Webpack 4, GraphQL Code Generator, React Router 4, PostCSS, SSR
Stars: ✭ 1,833 (+2220.25%)
Mutual labels:  universal, hot-reload

universal-hot-reload

Circle CI npm version npm downloads npm npm

Easily hot reload your server, client or universal apps 👏

Why this package?

  • Setup hot reload for your app in four lines of code or less.
  • Supports server, client and universal hot reloads!
  • Works with react, typescript, graphql and nexus.

This should be used in development only!

Installation

yarn add universal-hot-reload -D

Quickstart: server only

To hot reload graphql servers and express servers without ssr, create index.js and server.js like below. For graphql, only express-graphql and apollo-server are supported for now.

index.js

const { serverHotReload } = require('universal-hot-reload');

// server.js is where you export your http.server instance (see below) 
serverHotReload(require.resolve('./server.js'));

server.js

// You'll need to export default an instance of http.server so universal-hot-reload
// can restart your server when changes are detected.

// For express or express-graphql
export default app.listen(PORT, () => console.log(`Listening at ${PORT}`));

// For apollo-server
const server = new ApolloServer({ typeDefs, resolvers });
server.listen().then(() => console.log(`Listening at ${PORT}`));
export default server.httpServer;

Run your app:

node index.js

Quickstart: universal apps

To hot reload a universal app, create index.js like below and follow the same steps as Quickstart: server only.

index.js

const UniversalHotReload = require('universal-hot-reload').default;

// supply your own webpack configs
const serverConfig = require('../webpack.config.server.js');
const clientConfig = require('../webpack.config.client.js');

// the configs are optional, you can supply either one or both.
// if you omit say the server config, then your server won't hot reload.
UniversalHotReload({ serverConfig, clientConfig });

Advanced

If you use the serverHotReload function then you won't need to supply your own server webpack config. universal-hot-reload uses a default server webpack config so you don't have to supply your own.

If you want to use your own custom server webpack config or if you want to hot reload your universal app, then you'll need to supply your own webpack configs. Follow the lines marked Important.

  1. Your server webpack config should look like this:

    const path = require('path');
    const nodeExternals = require('webpack-node-externals');
    
    module.exports = {
      mode: 'development',
      devtool: 'source-map',
      entry: './src/server/server.js',
      target: 'node', // Important
      externals: [nodeExternals()], // Important
      output: {
        path: path.resolve('dist'),
        filename: 'serverBundle.js',
        libraryTarget: 'commonjs2' // Important
      },
      // other webpack config
    };
  2. Your client webpack config should look like this:

    const path = require('path');
    const webpackServeUrl = 'http://localhost:3002';
    
    module.exports = {
      mode: 'development',
      devtool: 'source-map',
      entry: './src/client/index',
      output: {
        path: path.resolve('dist'),
        publicPath: `${webpackServeUrl}/dist/`, // Important: must be full path with trailing slash
        filename: 'bundle.js'
      },
      // other webpack config
    };
  3. Create an index.js file:

    const UniversalHotReload = require('universal-hot-reload').default;
    
    // You can provide only a server or a client config or both. 
    const serverConfig = require('../webpack.config.server.js');
    const clientConfig = require('../webpack.config.client.js');
    
    // Omitting a config means that side of your app won't hot reload.
    UniversalHotReload({ serverConfig, clientConfig });
  4. Lastly in your server entry file:

    import { getDevServerBundleUrl } from 'universal-hot-reload';
    import webpackClientConfig from 'path/to/webpack.config.client';
    
    // Important: gets webpack-dev-server url from your client config 
    const devServerBundleUrl = getDevServerBundleUrl(webpackClientConfig);
    
    // Important: feed the url into script src
    const html = `<!DOCTYPE html>
                <html>
                  <body>
                    <div id="reactDiv">${reactString}</div>
                    <script src="${devServerBundleUrl}"></script>
                  </body>
                </html>`;
                
    // Important: the listen method returns a http.server object which must be default exported
    // so universal-hot-reload can access it
    export default app.listen(PORT, () => {
      log.info(`Listening at ${PORT}`);
    });
  5. Run your app!

    node index.js

Examples

For graphql, check this example with nexus, apollo server and typescript. Only express-graphql and apollo-server are supported right now. graphql-yoga does not expose its http.server instance and so it's not hot-reloadable this way for now.

For universal webpack apps, check the react example for a fully working spa with react and react-router.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].