How to use the fusion-core.CriticalChunkIdsToken.optional function in fusion-core

To help you get started, we’ve selected a few fusion-core 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 fusionjs / fusionjs / fusion-react / src / index.js View on Github external
);
    }
    const getService = token => {
      // $FlowFixMe
      const provides = this.getService(token);
      const isRequiredToken = Boolean(token.optional);
      if (typeof provides === 'undefined' && isRequiredToken) {
        throw new Error(
          `Token ${token.name} not registered or registered plugin does not provide a service. To use an optional plugin, use \`Token.optional\`.`
        );
      }
      return provides;
    };
    const renderer = createPlugin({
      deps: {
        criticalChunkIds: CriticalChunkIdsToken.optional,
        skipPrepare: SkipPrepareToken.optional,
      },
      provides({skipPrepare}) {
        return (el: React.Element<*>, ctx) => {
          return (skipPrepare ? Promise.resolve() : prepare(el)).then(() => {
            if (render) {
              return render(el, ctx);
            }
            if (__NODE__) {
              return serverRender(el);
            } else {
              return clientRender(el);
            }
          });
        };
      },
github fusionjs / fusionjs / fusion-cli / plugins / ssr-plugin.js View on Github external
runtimeChunkIds,
  initialChunkIds, // $FlowFixMe
} from '../build/loaders/chunk-manifest-loader.js!'; // eslint-disable-line

import modernBrowserVersions from '../build/modern-browser-versions.js';

/*::
import type {SSRBodyTemplateDepsType, SSRBodyTemplateType} from './types.js';
declare var __webpack_public_path__: string;
*/

/* eslint-disable-next-line */
const SSRBodyTemplate = createPlugin/*::  */(
  {
    deps: {
      criticalChunkIds: CriticalChunkIdsToken.optional,
      routePrefix: RoutePrefixToken.optional,
    },
    provides: ({criticalChunkIds, routePrefix}) => {
      return ctx => {
        const {htmlAttrs, bodyAttrs, title, head, body} = ctx.template;
        const safeAttrs = Object.keys(htmlAttrs)
          .map(attrKey => {
            return ` ${escape(attrKey)}="${escape(htmlAttrs[attrKey])}"`;
          })
          .join('');

        const safeBodyAttrs = Object.keys(bodyAttrs)
          .map(attrKey => {
            return ` ${escape(attrKey)}="${escape(bodyAttrs[attrKey])}"`;
          })
          .join('');
github fusionjs / fusion-cli / plugins / ssr-plugin.js View on Github external
import {
  chunks,
  runtimeChunkIds,
  initialChunkIds, // $FlowFixMe
} from '../build/loaders/chunk-manifest-loader.js!'; // eslint-disable-line

/*::
import type {SSRBodyTemplateDepsType, SSRBodyTemplateType} from './types.js';
declare var __webpack_public_path__: string;
*/

/* eslint-disable-next-line */
const SSRBodyTemplate = createPlugin/*::  */(
  {
    deps: {
      criticalChunkIds: CriticalChunkIdsToken.optional,
      routePrefix: RoutePrefixToken.optional,
    },
    provides: ({criticalChunkIds, routePrefix}) => {
      return ctx => {
        const {htmlAttrs, bodyAttrs, title, head, body} = ctx.template;
        const safeAttrs = Object.keys(htmlAttrs)
          .map(attrKey => {
            return ` ${escape(attrKey)}="${escape(htmlAttrs[attrKey])}"`;
          })
          .join('');

        const safeBodyAttrs = Object.keys(bodyAttrs)
          .map(attrKey => {
            return ` ${escape(attrKey)}="${escape(bodyAttrs[attrKey])}"`;
          })
          .join('');