0.1.0 • Published 2 years ago

snack-require-context v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

snack-require-context

Support for require.context in Snack is tricky, since we have no access to any bundler when executing code from users. This package helps re-implementing this API in Snack, for both libraries (through Snackager) and user-provided code (through Runtime).

Usage

This package contains code for both the Snack Runtime and Snackager.

Snackager

The only implementation for Snackager is the transformation of require.context statements to require('<virtual-module>'). This is done through Babel and converts the full require.context signature to a path with query parameter. Once this code is evaluated within the app, the Snack Runtime knows it's a virtual module and generates the result.

Runtime

The require.context system is more integrated in the Snack Runtime. It needs to recognize virtual module requests, generate the require.context result based on the current project, and create new require.context requests when using Expo Router. Here are the different integration points of the require.context system within the Snack Runtime.

Contributing

This package has a few commands, mainly to build, analyze and build for publishing.

  • yarn dev → Builds an unoptimized development build.
  • yarn build → Builds an optimized production build.