# @render-kit/schema-loader

> Webpack loader for render schema

Latest version **0.2.0** (published 2021-09-15) · UNLICENSED license · 0 weekly downloads

## Install

```sh
npm install @render-kit/schema-loader
pnpm add @render-kit/schema-loader
yarn add @render-kit/schema-loader
bun add @render-kit/schema-loader
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2021-09-15 |
| First published | 2021-06-02 |
| Weekly downloads | 0 |
| License | UNLICENSED |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 23.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | ByzanTeam |
| Maintainers | byzan.dev |

## Links

- npm: https://www.npmjs.com/package/@render-kit/schema-loader
- Repository: https://github.com/Byzanteam/jet-toolkit
- Homepage: https://github.com/Byzanteam/jet-toolkit#readme
- Issues: https://github.com/Byzanteam/jet-toolkit/issues
- npm.io page: https://npm.io/package/@render-kit/schema-loader

## Dependencies (2)

- [change-case](https://npm.io/package/change-case.md) ^4.1.2
- [jsonc-parser](https://npm.io/package/jsonc-parser.md) ^3.0.0

## Recent versions

- 0.2.0 (latest) — 2021-09-15
- 0.1.4 — 2021-08-16
- 0.1.3 — 2021-08-02
- 0.1.2 — 2021-06-28
- 0.1.1 — 2021-06-18
- 0.1.0 — 2021-06-02

## README

# @render-kit/schema-loader

## Installation

```sh
npm install -D @render-kit/schema-loader
```
```sh
yarn add -D @render-kit/schema-loader
```

## Usage
```js
const { SchemaLoaderPlugin } = require('@render-kit/schema-loader')

module.exports = {
  module: {
    rules: [
      {
        test: /schema.jsonc$/,
        use: '@render-kit/schema-loader',
      },
    ],
  },
  plugins: [
    new SchemaLoaderPlugin(),
  ],
}
```

## Options

### entry

`string = 'entry.js'`

The file name of remote entry.

### manifest

`string = 'jet-cells-manifest.json'`

The file name of manifest.

### transform

`Function`

Transform schemas before emit.

## Example

```js
// -> webpack.config.js
/**
 * Customize manifest path.
 */
const { readdirSync } = require('fs')
const { SchemaLoaderPlugin } = require('@render-kit/schema-loader')
const { pascalCase } = require('change-case')
const { ModuleFederationPlugin } = require('webpack').container

const REMOTE_ENTRY = 'remoteEntry.js'

/**
 * @param {string} directory
 * @returns {string}
 */
function resolveCellName(directory) {
  return pascalCase(directory)
}

/**
 * @param {string} path
 * @returns {object}
 */
function resolveExposes(path) {
  return readdirSync(path, { withFileTypes: true }).reduce((acc, file) => {
    if (file.isFile()) return acc
    return Object.assign(acc, {
      [resolveCellName(file.name)]: `./${path}/${file.name}`,
    })
  }, {})
}

/**
 * @param {string} name
 * @returns {string}
 */
function sanitizeName(name) {
  return name
    .replace(/@/g, '_at_')
    .replace(/-/g, '_dash_')
    .replace(/\//g, '_slash_')
}

module.exports = {
  module: {
    rules: [
      {
        test: /schema.jsonc$/,
        use: '@render-kit/schema-loader',
      },
    ],
  },
  plugins: [
    new SchemaLoaderPlugin({
      entry: REMOTE_ENTRY,
    }),
    new ModuleFederationPlugin({
      name: sanitizeName(process.env.npm_package_name),
      filename: REMOTE_ENTRY,
      exposes: resolveExposes('src'),
    }),
  ],
}
```

```bash
## input
$ tree src
src
└── input
    ├── index.ts
    ├── input.vue
    └── schema.jsonc

1 directory, 3 files
```

```bash
## output
$ tree dist
dist
├── 144.js
├── 393.js
├── 689.js
├── input.json
├── jet-cells-manifest.json
└── remoteEntry.js

0 directories, 6 files
## jet-cells-manifest.json
$ cat dist/jet-cells-manifest.json
{
  "directory": "dist",
  "entry": "remoteEntry.js",
  "cells": {
    "Input":"input.json"
  }
}
```

---
_Source: https://npm.io/package/@render-kit/schema-loader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
