0.0.1-RC.3 • Published 1 year ago

@enhance/loader v0.0.1-RC.3

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

!IMPORTANT
This library is a work-in-progress. It supports a restructured version of @enhance/arc-plugin-enhance and will be helpful in other contexts as well. It is not yet ready for use in production.

@enhance/loader aka "Enahnce Loader"

Enhance Loader's main job is to provide configuration for @enhance/core by scanning the file system for routes (apis + pages) elements (+ components).

Usage

npm i @enhance/loader
import loadAppConfig from '@enhance/loader'
import createCore from '@enhance/core'

const basePath = process.cwd()
const appConfig = await loadAppConfig({ basePath })

const app = createCore({
  ...appConfig,
  head (payload) {
    const { store } = payload
    return `<head><title>${store.title}</title></head>`
  },
  state: {},
})

const response = await app.routeAndRender({ path: '/' })
const { html, headers, ...rest } = response

Architect Sample

the gist in an Arc handler...

import arc from '@architect/functions'
import loadAppConfig from '@enhance/loader'
import createCore from '@enhance/core'

const basePath = process.cwd()
const appConfig = await loadAppConfig({ basePath })
const app = createCore(appConfig)

export const handler = arc.http.bind(app.routeAndRender)

API

Better documentation incoming.
For now...

Options as .d.ts

type EnhanceLoadOptions = {
  basePath: string;
  apiPath?: string;
  pagesPath?: string;
  elementsPath?: string;
  componentsPath?: string;
  debug?: boolean;
};

// src/types.d.ts contains expanded definitions

What it does

  • scan the file system as fast as possible
  • return "deferred" route resources
  • import all elements

What it does NOT

  • create a router, server, or any other runtime code
  • run in any environment other than Node.js

TODO

0.1.0-alpha.0

1 year ago

0.0.1-RC.2

1 year ago

0.0.1-RC.3

1 year ago

0.0.1-RC.1

1 year ago

0.0.1-RC.0

1 year ago