0.1.1 • Published 4 days ago

nitro-public-module v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 days ago

nitro-public-module

nitro module for better public compatibility

README 🦉

简体中文 | English

Usage

install

npm i nitro-public-module -D

Configuration Module

nuxt

// nuxt.config.ts
import nitroPublic from "nitro-public-module";

export default defineNuxtConfig({
  nitro: {
    modules: [nitroPublic()],
  },
});

nitro

// nitro.config.js
import nitroPublic from "nitro-public-module";

export default defineNitroConfig({
  modules: [nitroPublic()],
});

preset

// nitro.config.js
import nitroPublic from "nitro-public-module";

export default defineNitroConfig({
  modules: [
    nitroPublic({
      // support "spa", "ssg","fallback" and false (disable),default to "fallback"
      preset: "fallback",
    }),
  ],
});

fallback

Support rollback of any file in production environment (even if dynamically added to public)

spa

Allow you to run spa app in public

ssg

Allow you to run ssg app in public

custom

  1. disable preset first
// nitro.config.js
import nitroPublic from "nitro-public-module";

export default defineNitroConfig({
  modules: [
    nitroPublic({
      preset: false,
    }),
  ],
});
  1. create custom middleware
// middleware/public-fallback.ts
import { createPublicFallbackMiddleware } from "#nitro-public";

export default createPublicFallbackMiddleware((withoutSlashPathname) => {
  // some logic...

  return {
    file: "index.html", // your file
    contentType: "text/html", // If not set, it will be inferred from the extname of the file
    withPublicDir: true, // Default to true, help you process the path
  };
});
virtual

In addition to providing createPublicFallbackMiddleware, #nitro-public also offers publicDir and serverDir

import {
  createPublicFallbackMiddleware,
  publicDir,
  serverDir,
} from "#nitro-public";

All functions are type safe and support development and production environments (for pure node runtime)

License

Made with markthree

Published under MIT License.

0.1.1

4 days ago

0.1.0

1 month ago

0.0.10

3 months ago

0.0.11

3 months ago

0.0.9

3 months ago

0.0.8

3 months ago

0.0.7

3 months ago

0.0.6

3 months ago

0.0.5

3 months ago

0.0.4

4 months ago

0.0.3

4 months ago

0.0.2

4 months ago

0.0.1

4 months ago