GitXplorerGitXplorer
m

webcontainer-fst

public
9 stars
1 forks
0 issues

Commits

List of commits on branch main.
Unverified
87f7a09884b1037f70af6ec7e0cad080f33a3675

Add packageManager field

mmorinokami committed a month ago
Unverified
4ecad6713f1874c31beed572340de50a3f283f0d

Update CI

mmorinokami committed a month ago
Unverified
6036e50d3e48f2f882cc4216eef4f73d2c88a1bb

Update packages

mmorinokami committed a month ago
Unverified
40557582c9551e79430f56cf7f77f567ef2cdbe6

0.0.2

mmorinokami committed 2 years ago
Verified
b1737722ccf6062f21d79805517e97677ed6297b

Update README.md

mmorinokami committed 2 years ago
Verified
1493336cdb557ce12020d014398ec094dea9d26d

Update README.md

mmorinokami committed 2 years ago

README

The README file for this repository.

webcontainer-fst

webcontainer-fst creates a WebContainer-compatible FileSystemTree from a given path.

Demo

Suppose the directory you want to mount on WebContainer has the following file structure:

src
├── index.js
└── package.json

To obtain the FileSystemTree corresponding to this src directory, execute the createFst function as follows:

$ cat build-files.js 
import { createFst } from 'webcontainer-fst';

const fst = await createFst('./src');
console.log(JSON.stringify(fst, null, 2));

$ node build-files.js 
{
  "index.js": {
    "file": {
      "contents": "import express from 'express';\nconst app = express();\nconst port = 3111;\n\napp.get('/', (req, res) => {\n  res.send('Welcome to a WebContainers app! 🥳');\n});\n\napp.listen(port, () => {\n  console.log(`App is live at http://localhost:${port}`);\n});"
    }
  },
  "package.json": {
    "file": {
      "contents": "{\n  \"name\": \"example-app\",\n  \"type\": \"module\",\n  \"dependencies\": {\n    \"express\": \"latest\",\n    \"nodemon\": \"latest\"\n  },\n  \"scripts\": {\n    \"start\": \"nodemon index.js\"\n  }\n}"
    }
  }
}

The fst variable created here can be saved to a file and later mounted on WebContainer.

Installation

npm install webcontainer-fst