A demo of using the new require.context syntax in Expo with Metro bundler

Overview

Metro Context Modules Demo

This is a demo of using the experimental 'Context Module' (require.context) feature in Metro bundler.

Setup

metro.config.js

const { getDefaultConfig } = require("expo/metro-config");

const config = getDefaultConfig(__dirname);

config.transformer = {
  // `require.context` support
  unstable_allowRequireContext: true,
};

module.exports = config;

At the moment, you'll need to force the Metro versions in your package.json:

{
  "resolutions": {
    "metro": "0.72.1",
    "metro-babel-transformer": "0.72.1",
    "metro-cache": "0.72.1",
    "metro-cache-key": "0.72.1",
    "metro-config": "0.72.1",
    "metro-core": "0.72.1",
    "metro-hermes-compiler": "0.72.1",
    "metro-minify-uglify": "0.72.1",
    "metro-react-native-babel-preset": "0.72.1",
    "metro-react-native-babel-transformer": "0.72.1",
    "metro-resolver": "0.72.1",
    "metro-source-map": "0.72.1",
    "metro-symbolicate": "0.72.1",
    "metro-transform-plugins": "0.72.1",
    "metro-transform-worker": "0.72.1"
  }
}

If you want to add TypeScript support to require.context, include the types/metroRequire.d.ts, then extend the tsconfig.json:

{
  "extends": "expo/tsconfig.base",
  "include": ["./types/metroRequire"]
}

Usage

  • Run yarn start
  • Add files to the app/ folder to see the UI update dynamically.

For more info, see the Webpack docs on require.context.

const ctx = require.context("./app");

const myModule = ctx[ctx.keys()[0]];
You might also like...

📦 🍣 Zero-config JS bundler for ESM, CommonJS, and .d.ts outputs. (Forked from pkgroll)

📦 🍣 puild (A fork of pkgroll) Write your code in ESM & TypeScript and bundle it to get ESM, CommonJS, and type declaration outputs with a single com

Sep 6, 2022

The aim of this project is to restructure the Awesome books app code by using ES6 syntax and organising the workspace using modules.

Awesome-Books-ES6 The aim of this project is to restructure the Awesome books app code by using ES6 syntax and organising the workspace using modules.

Aug 18, 2022

In this project, I built a basic website that allows users to add/remove books from a list using HTML/CSS to build the app and JavaScript to add functionalities. This project was organized using modules and ES6 syntax implemented.

Awesome books: with ES6 Description the project. Built With HTML CSS JAVASCRIPT Live Demo (if available) Live Demo Link Getting Started This is an exa

Sep 9, 2022

Todo-App with React-Context

View on Heroku : [https://todo-app-context.herokuapp.com/] Getting Started with Create React App This project was bootstrapped with Create React App.

Jan 2, 2022

🚀🚀 A Shopify embedded app starter template, with updated dependencies, session storage, app context and examples for basic functionalities.

Shopify Node App Starter This is a starter template for embedded shopify apps based on the shopify cli node app. Contributions to create the perfect s

Jan 8, 2023

Context-Full Web Component Library

Context-Full Web Component Library

CWCO Contextfull Web Component Library created to improve native Web Component APIs user experience with: ✅ No Build Required! ✅ Works with other libr

Jan 2, 2023

Context-aware smart contracts for blockchain IoT systems

Context-aware smart contracts for blockchain IoT systems It contains 2 directories: contracts: contains the ContextAwareSmartContract.sol contract wit

Jun 17, 2022

Context-carrying logger with conditional methods.

logger Provides a simple logging interface as well as a LogContext class which carries a context around. Installation npm install @rocicorp/logger Us

May 20, 2022

mock APIs, intelligently, with context, and perform other stuff as well

@sasta-sa/project mock APIs, intelligently, with context, and perform other stuff as well 😄 Setting up Clone the project git clone https://github.com

Jan 27, 2022
Comments
  • Bump decode-uri-component from 0.2.0 to 0.2.2

    Bump decode-uri-component from 0.2.0 to 0.2.2

    Bumps decode-uri-component from 0.2.0 to 0.2.2.

    Release notes

    Sourced from decode-uri-component's releases.

    v0.2.2

    • Prevent overwriting previously decoded tokens 980e0bf

    https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.1...v0.2.2

    v0.2.1

    • Switch to GitHub workflows 76abc93
    • Fix issue where decode throws - fixes #6 746ca5d
    • Update license (#1) 486d7e2
    • Tidelift tasks a650457
    • Meta tweaks 66e1c28

    https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.1

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Owner
Evan Bacon
King of coding (sometimes mostly not). ★ Please star Expo on GitHub! Follow me on Twitter for updates 🥓
Evan Bacon
Talk to anyone connected to your network, be it LAN or your hotspot. Doesn't require internet.

Apophis CLI to talk to anyone connected to your network, be it LAN or your hotspot. Doesn't require internet. Installation Make sure you have NodeJS (

Saurav Pal 3 Oct 16, 2022
Nftix-demo-ui - Demo UI used in my NFT course on Egghead.io

NFTix Demo UI This repository contains the UI used for my Egghead course on building a NFT ticketing system ?? ?? If you're watching the videos, use t

Ryan Harris 10 Dec 17, 2022
A template for a vanilla(no ui-framework) project with webgi engine in typescript using parcel bundler.

WebGi starter project A template for a vanilla(no ui-framework) project with webgi engine in typescript using parcel bundler. For the latest version a

null 40 Jan 3, 2023
A template for buildind scrollable landing pages with Gsap, ScrollTrigger and webgi engine in typescript using parcel bundler.

Threejs + GSAP + WEBGi 100% Free Course This is a template used in my fast course "building scrolable pages with ScrollTrigger and Threejs" for a vani

Anderson Mancini 62 Dec 17, 2022
ChatBox is a WhatsApp Bussiness Clone that built with React Native & Expo

chatbox (...ongoing) ChatBox is a WhatsApp Business Clone built with React Native & Expo. UI (DARK MODE) UI (LIGHT MODE) Tech Stack used: FRONTEND Rea

Bentil Shadrack 22 Dec 19, 2022
NX monorepo showing the TMDB Watchlist mobile app with Expo, tRPC, Next, and Prisma

tmdb-watchlist-prisma This app uses TMDB to retrieve a list of Now Playing movies. You can add/remove movies to track which ones you've watched. There

Mat Warger 65 Dec 28, 2022
Kaol Stack - Prisma, Expo, Next, TRPC, Solito, Tailwind - A monorepo template for a truly universal app

Kaol Stack ?? About A monorepo with Prisma, Next.js, Expo, tRPC, Authentication and Solito setup and configured to work together. With this setup you

Matheus Vicente 187 Dec 21, 2022
Finance-Tracker - A basic finance-tracker application built using Next.js, React Hooks and Context API

Next.js + Tailwind CSS Example This example shows how to use Tailwind CSS (v3.0) with Next.js. It follows the steps outlined in the official Tailwind

Osemwengie Benjamin 1 Jan 2, 2022
lua-pack is an advanced lua bundler similar to webpack made for lua 5.1+ written in js

lua-pack is an advanced lua bundler similar to webpack made for lua 5.1+ written in js that makes working on large scale projects easy and fast. it takes all the files in your project and packs them into a single production ready file.

Chris 10 May 14, 2022
📦 🍣 Zero-config JS bundler for ESM, CommonJS, and .d.ts outputs

pkgroll Write your code in ESM & TypeScript and bundle it to get ESM, CommonJS, and type declaration outputs with a single command! Features Zero conf

hiroki osame 153 Dec 23, 2022