Command-line Interface
The command-line interface (CLI) provides the primary means to interact with the ReChunk service, enabling the hosting and distribution of your bundled chunks.
Initialize
The init
command initializes a new ReChunk project via the CLI. To create a new ReChunk project, you must provide the host, username, and password for basic authentication. Upon executing this command, a rechunk.json
configuration file will be generated in the root directory of your React Native project. This configuration file will be used to automatically configure your React Native app with the ReChunk instance.
yarn rechunk init --host http://localhost:3000 --username rechunk --password aC00Lpr0ject
npm run rechunk init --host http://localhost:3000 --username rechunk --password aC00Lpr0ject
pnpm rechunk init --host http://localhost:3000 --username rechunk --password aC00Lpr0ject
bun run rechunk init --host http://localhost:3000 --username rechunk --password aC00Lpr0ject
This command assumes that your ReChunk service is running on localhost
at port 3000
. The username and password provided are used for basic authentication with the initialization endpoint.
This command must be executed before running any other commands or utilizing this library in your React Native project.
Publish
Chunks can only be bundled via the publish
command. Only chunks that are registered in the rechunk.json
can be published; this is required because the path must be defined for each chunk. The publish command will bundle all the non-registered dependencies into a single string of code to be pushed to the ReChunk service. If there are additional dependencies that should not be bundled that are not part of your package.json
i.e. shared aliased source code that can be registered in the rechunk.json
via the external
attribute.
{ "$schema": "https://crherman7.github.io/rechunk/schema.json", "project": "prototypical-pigs-interlay", "readKey": "read-5456fcad-99bd-4328-bfc4-0cb597ffbc4d", "writeKey": "write-9bd47fc2-323e-4f74-9082-2abfb86582b4", "publicKey": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArk92wo3nc7AShy2c860h\nojRACKTnYGbB1NPRezyZ40Lk9p/myZ02ZpmVDGlMtWgqgIOoufUwPTa9LkmjFUgg\nYkhDHZzokiJjZ9PseRXr4+63p8MSvOmQvoQMqSO2mBEuXTks4tTNx/AySWqV9GDC\nMeM+VFKtQULuxgQSNJ1LDIu8ofpeKDB2bivV8phrLzRSM4TWuCu9u9gWxsUbTihR\nLyicJvmx44NBmdr9N0WIOh/15vAYieiY8MsZE7B8St0x5jgDT4taUzTd8R0RyDw/\nO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DSRqpdl/eX2t4vMYbdfHvvtzy01MccKrQ2\nhADX/PgVAe/8n1/vxftK5cKAUapq0gpS8/1mRuTeRZ9a7HAZvpNuYEKhlRsSOzNg\nYYqNmq9F33kxRjsdm6RrYMMyk8v8pIuyFTaZY+MdIRDt306a2VK4EAQxS5G+wTr6\nOgOM4fxQowKBgGawZ5gf7PJ7lRu2r+XBJC7bBdgp7UsUULRnLPucpYHc0ehLjySg\npdo643jBP7XbM3Xx8D3iyUjs4VJtWaxkhtfKBOox8pVDtgKRZmnQ7/jGg/cbbyi8\nKrjOdryyI1oiiFNPthG8t4OhruozTtW0QildMCddeBuAy5+Q+E0nLRY/AoGAFxXR\nAGN9uDs8J1w9nTVcee3ZCVVO4sXBcTa+zPel2NCUo1xv8OgAdbGRz/qnRgD3RzIo\nQMFJwSlNnHLWv8zPbM++oPS4uyCqvEsZJgC0e2xUZtd6B/8dZviBlZzqSTtbZtqz\nWtW/imQl8qeQfqmbTj/b5fmQ76tRKUWTPDVXORcCgYEArx0LII/G1luLj/z2bvhz\nA5OXyUL7ka2wJqmpb0XdFP+PPIsud5GXf2uG9GTkhBHnwuakXW8UdB/4pwEtAYRS\nGndITg+KPDwTvuz6P51MQM6wd1922UKjTl3BY+7CzaWCuBGV/yfFjpsWtoSQJvSY\nDCwpHpF7v/6fhQU/Y2ZnI84=\n-----END PRIVATE KEY-----\n", "entry": {"foo": "./src/shared/remote-ui/Remote.tsx"}, "external": ["@/shared"], "host": "http://localhost:3000"}
Once the chunks have been registered they can be published via the publish
command and be utilized within the application.
yarn rechunk publish --chunk foo
npm run rechunk publish --chunk foo
pnpm rechunk publish --chunk foo
bun run rechunk publish --chunk foo
Unpublish
If a chunk becomes unnecessary or needs to be removed, the unpublish
command can be used to delete this chunk from the ReChunk service.
yarn rechunk unpublish --chunk foo
npm run rechunk unpublish --chunk foo
pnpm rechunk unpublish --chunk foo
bun run rechunk unpublish --chunk foo
List
The list
command can be utilized to visualize which chunks have been published and are available to use in the application.
yarn rechunk list
npm run rechunk list
pnpm rechunk list
bun run rechunk list
Development Server
Before publishing a chunk, it can be beneficial to test and iterate quickly. The development server is particularly useful for this process. The development server uses your configuration file to bundle chunks on the fly, without interacting with a hosted ReChunk service. It employs the same bundling logic, providing a local experience that mirrors the hosted environment. The development server command will also temporarily update the rechunk.json
configuration to point the host to the development server.
yarn rechunk dev-server
npm run rechunk dev-server
pnpm rechunk dev-server
bun run rechunk dev-server
Once the dev-server
command has been executed, you can start the React Native application.