Skip to main content

webpack

import { webpack } from '@dr.pogodin/react-utils';

Encapsulates Webpack-related utilities.

Functions

  • requireWeak() - Requires a module at server side, and prevents it from being bundled by Webpack.
  • resolveWeak() - Resolves a module path with the help of Babel module resolver, thus the same way the resolution works for the normal require().

Functions

requireWeak()

webpack.requireWeak(modulePath, basePath): object

Implements server-side loading of the specified JS module in the way which prevents it from being bundled into the client-side code by Webpack.

  • Server-side: the modulePath argument is processed by Babel module resolver; if basePath is given, the resulting module path is additionally resolved from the base path using path.resolve(); the module is then loaded from the resulting path, and returned, similar to the regular require(), but invisible to Webpack, hence the module required this way is not bundled into the client side code. If the module could not be resolved, or the loading failed for other reason, requireWeak() returns null.

  • Client-side: always returns null.

Changes across dr.pogodin/react-utils versions:
  • v1.14.0:
    • Safe to call at the client side, and always returns null there.
    • The modulePath argument is automatically processed by Babel module resovler.
    • basePath argument introduced.

resolveWeak()

webpack.resolveWeak(modulePath): string

Resolves modulePath module path with the help of Babel module resolver, thus the same way the resolution works for the normal require().

Arguments & Result

  • modulePath - string - Module path.
  • Returns string - The resolved relative path to the module.