How to use the webpack-hot-middleware function in webpack-hot-middleware

To help you get started, we’ve selected a few webpack-hot-middleware examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github elsewhencode / react-redux-saucepan / src / server / index.dev.js View on Github external
import { PORT, HOST, ASSETS_PATH } from '../../config';

const app: express$Application = express();
app.use(express.static('static'));

const compiler = webpack(webpackConfig);

app.use(
  webpackDevMiddleware(compiler, {
    heartbeat: 2000,
    log: false,
    publicPath: webpackConfig.output.publicPath,
    stats: { colors: true },
  }),
);
app.use(webpackHotMiddleware(compiler));

// just throws back an empty html page.
app.get('*', (req: express$Request, res: express$Response) => {
  res.status(200).send(
    html({
      'app.css': `${ASSETS_PATH}app.css`,
      'app.js': `${ASSETS_PATH}app.js`,
      'vendor.js': '',
    }),
  );
});

app.listen(PORT, HOST, (err) => {
  if (err) {
    // eslint-disable-next-line no-console
    console.log(err);
github react-cosmos / react-cosmos / packages / react-cosmos / src / server / web / webpack / attach-webpack.js View on Github external
const onWebpackDone: Promise = new Promise(resolve => {
    webpackCompiler.plugin('done', () => resolve(true));
  });

  console.log('[Cosmos] Building webpack...');
  const wdmInst = webpackDevMiddleware(webpackCompiler, {
    // publicPath is the base path for the webpack assets and has to match
    // webpack.output.path
    publicPath: getRootUrl(publicUrl),
    logLevel: 'warn'
  });

  app.use(wdmInst);

  if (hot) {
    app.use(webpackHotMiddleware(webpackCompiler));
  }

  function stopWebpack() {
    return promisify(wdmInst.close.bind(wdmInst))();
  }

  return { onWebpackDone, stopWebpack };
}
github CircleCI-Public / circleci-demo-javascript-express / server / server.js View on Github external
import IntlWrapper from '../client/modules/Intl/IntlWrapper';

// Webpack Requirements
import webpack from 'webpack';
import config from '../webpack.config.dev';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';

// Initialize the Express App
const app = new Express();

// Run Webpack dev server in development mode
if (process.env.NODE_ENV === 'development') {
  const compiler = webpack(config);
  app.use(webpackDevMiddleware(compiler, { noInfo: true, publicPath: config.output.publicPath }));
  app.use(webpackHotMiddleware(compiler));
}

// React And Redux Setup
import { configureStore } from '../client/store';
import { Provider } from 'react-redux';
import React from 'react';
import { renderToString } from 'react-dom/server';
import { match, RouterContext } from 'react-router';
import Helmet from 'react-helmet';

// Import required modules
import routes from '../client/routes';
import { fetchComponentData } from './util/fetchData';
import posts from './routes/post.routes';
import dummyData from './dummyData';
import serverConfig from './config';
github younth / react-router-redux-mobile-spa / server.js View on Github external
stats: {
                    assets: false,
                    colors: true,
                    version: false,
                    hash: false,
                    timings: false,
                    chunks: false,
                    chunkModules: false
                },

                // for other settings see
                // http://webpack.github.io/docs/webpack-dev-middleware.html
            }),

            // bundler should be the same as above
            webpackHotMiddleware(bundler)
        ]
    },

    // no need to watch '*.js' here, webpack will take care of it for us,
    // including full page reloads if HMR won't work
    files: [
        'index.html'
    ]
});
github developer239 / react-apollo-graphql / server / middleware / dev.ts View on Github external
export const handleWebpackDevServer = (app: Express) => {
  // eslint-disable-next-line
  const webpackDevConfig = require('../../webpack/client/dev')

  const compiler = webpack(webpackDevConfig)

  app.use(
    webpackDevMiddleware(compiler, {
      publicPath: webpackDevConfig.output.publicPath,
    })
  )

  app.use(webpackHotMiddleware(compiler, { log: false }))

  return { compiler }
}
github DumDumGeniuss / react-universal-redux-starter-kit / src / server.js View on Github external
app.use(bodyParser.json());

if (process.env.NODE_ENV === 'development') {
	const compiler = webpack(webpackConfig);

	app.use(webpackDevMiddleware(compiler, {
		publicPath: '/dist',
		hot: true,
		filename: 'bundle.js',
		stats: {
			colors: true,
		},
		historyApiFallback: true,
	}));

	app.use(webpackHotMiddleware(compiler, {
		log: console.log,
		path: '/__webpack_hmr',
		heartbeat: 10 * 1000,
	}));
}

function handleReactRender(req, res, initState = {}, assets = {}) {
	const store = createStore(reducers, initState, applyMiddleware(thunk));
	const location = createLocation(req.originalUrl);

	match({ routes, location }, (error, redirectLocation, renderProps) => {
		if (error) {
			console.error(error);
			return res.status(500).end('Server Error');
		}
		if (!renderProps) {
github Kong / insomnia / webpack / server.js View on Github external
import {parse as urlParse} from 'url';

import config from './webpack.config.development.babel';

const app = express();
const compiler = webpack(config);

app.use(webpackDevMiddleware(compiler, {
  publicPath: config.output.publicPath,
  noInfo: true,
  stats: {
    colors: true
  }
}));

app.use(webpackHotMiddleware(compiler));

const parsedUrl = urlParse(config.output.publicPath);
app.listen(parsedUrl.port, parsedUrl.hostname, err => {
  if (err) {
    console.error(err);
    return;
  }

  console.log(`Listening at http://${parsedUrl.hostname}:${parsedUrl.port}`);
});
github GeReV / mpdisco / tools / start.js View on Github external
      .map(compiler => webpackHotMiddleware(compiler));
github wix / wix-react-native-storybook-template / storybook-react-native / server / middleware.js View on Github external
const compiler = webpack(config);
  const devMiddlewareOptions = {
    noInfo: true,
    publicPath: config.output.publicPath,
    watchOptions: config.watchOptions || {},
  };

  const router = new Router();
  const middlewareFn = getMiddleware(configDir);
  middlewareFn(router);

  router.use(webpackDevMiddleware(compiler, devMiddlewareOptions));

  if (!isProd) {
    router.use(webpackHotMiddleware(compiler));
  }

  router.get('/', (req, res) => {
    res.set('Content-Type', 'text/html');
    res.sendFile(path.join(`${__dirname}/public/index.html`));
  });

  return router;
}
github bhj / karaoke-forever / server / middleware / webpack-hmr.js View on Github external
export default function (compiler, opts) {
  debug('Enable Webpack Hot Module Replacement (HMR).')

  const middleware = WebpackHotMiddleware(compiler, opts)
  return async function koaWebpackHMR (ctx, next) {
    let hasNext = await applyExpressMiddleware(middleware, ctx.req, ctx.res)

    if (hasNext && next) {
      await next()
    }
  }
}