@before.js/server

    4.1.13 • Public • Published

    @before/server

    js-flybondi semantic-release js-semistandard-style code style: prettier

    yarn add @before/server
    yarn add @loadable/server react react-dom react-router-dom react-helmet

    Basic usage

    // ./src/routes.js
    import { asyncComponent } from '@before/client';
    import loadable from '@loadable/component';
    
    const Placeholder = () => <div>Loading</div>;
    
    const HomeContainerLoader = /* #__LOADABLE__ */ () =>
      import(/* webpackChunkName: "home" */ './pages/HomeContainer/HomeContainer.page');
    
    const routes = [
      {
        path: '/',
        exact: true,
        component: asyncComponent({
          LoadableComponent: loadable(HomeContainerLoader, { fallback: Placeholder }),
          loader: HomeContainerLoader
        })
      }
    ];
    
    export default routes;
    // ./src/server.js
    import express from 'express';
    import { render } from '@before/server';
    import routes from './routes';
    
    const assets = require(process.env.ASSETS_MANIFEST);
    
    const server = express();
    server
      .disable('x-powered-by')
      .use(express.static(process.env.PUBLIC_DIR))
      .get('/*', async (req, res) => {
        try {
          // Pass document in here.
          const html = await render({
            req,
            res,
            routes,
            assets,
            statsPath
          });
          res.send(html);
        } catch (error) {
          res.json(error);
        }
      });
    
    export default server;

    Chunk support

    Before.js use loadable-components to support server-side chunks/code-split.

    Install

    npm i @before.js/server

    DownloadsWeekly Downloads

    56

    Version

    4.1.13

    License

    MIT

    Unpacked Size

    301 kB

    Total Files

    34

    Last publish

    Collaborators

    • lfantone
    • flybondi-nelson