@shopify/mini-oxygen
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

Mini Oxygen

Getting Started

MiniOxygen is a local runtime that simulates Oxygen production. It is based on Cloudflare's workerd via Miniflare.

To use MiniOxygen within your app, follow these steps:

Add @shopify/mini-oxygen as a dev dependency of your app:

npm install --save-dev @shopify/mini-oxygen

Import it and create a new instance of Mini Oxygen:

import {createMiniOxygen} from '@shopify/mini-oxygen';

const miniOxygen = createMiniOxygen({
  workers: [
    {
      name: 'main',
      modules: true,
      script: `export default {
        async fetch() {
          const response = await fetch("https://hydrogen.shopify.dev");
          return response;
        }
      }`,
    },
  ],
});

Dispatch requests to MiniOxygen from the browser or any other environment:

const response = await miniOxygen.dispatchFetch('http://placeholder');
// Or with the following code via network request:
// const {workerUrl} = await miniOxygen.ready;
// const response = await fetch(workerUrl);

console.log(await response.text());

await miniOxygen.dispose();

Legacy Node.js Sandbox runtime

The previous Node.js sandbox runtime has been moved to the @shopify/mini-oxygen/node export. It is not recommended for new projects, but can be used as follows:

import {createMiniOxygen} from '@shopify/mini-oxygen/node';

const miniOxygen = createMiniOxygen({
  script: `export default {
  async fetch() {
     const response = await fetch("https://hydrogen.shopify.dev");
     return response;
  }
 }`,
});

const response = await miniOxygen.dispatchFetch('http://placeholder');

console.log(await response.text());

await miniOxygen.dispose();

Readme

Keywords

none

Package Sidebar

Install

npm i @shopify/mini-oxygen

Weekly Downloads

9,593

Version

3.0.1

License

MIT

Unpacked Size

169 kB

Total Files

41

Last publish

Collaborators

  • jaimie.rockburn
  • blittle
  • shopify-admin
  • maryharte
  • crisfmb
  • pmoloney89
  • netlohan
  • st999999
  • justin-irl
  • megswim
  • wcandillon
  • nathanpjf
  • shopify-dep
  • goodforonefare
  • lemonmade
  • vsumner
  • wizardlyhel
  • antoine.grant
  • tsov
  • andyw8-shopify
  • henrytao
  • hannachen
  • vividviolet
  • bpscott