For modules support (necessary for module workers), the node instance that spawns this module should be launched with the --experimental-vm-modules option. For a cross platform way of adding this flag to your runtime, you could take a look at Miniflare's implementation here.
To use Mini Oxygen within your app, follow these steps:
Add @shopify/mini-oxygen as a dev dependency of your app:
yarn add --dev @shopify/mini-oxygenor
npm install --save-dev @shopify/mini-oxygenMini Oxygen can then be loaded with:
import {startServer} from '@shopify/mini-oxygen';A Mini Oxygen server can then be activated with:
await startServer({<MiniOxygenPreviewOptions>})MiniOxygenPreviewOptions has the following attributes:
port: the TCP port used for the local web server on localhostworkerFile: path to the worker file related to the current dirassetsDir: path to the built assets directory related to the current dirpublicPath: URL or pathname for public/static assets that prefixes file namesproxyServer: proxy server address and port (:) to proxy requests tobuildCommand: a command to re-build the projectwatch: enable or disable rebuild on source file changesbuildWatchPaths: an array of directories to watch for changesautoReload: enables auto reload of the browser after re-buildingmodules: enables module syntax in the worker scriptenvPath: (optional) path to the .env file to be loaded automaticallyenv: specify environment variables available in the worker script
The following server hooks can be specified as part of the options:
onRequest: (optional) function taking inRequestparameteronReponse: (optional) function taking in parameters of typeRequestandResponseonResponseError: (optional) function that acceptsResponseand unknownerrorattribute.