https://github.com/markthree/nitro-public-module
nitro module for better public compatibility | 对于 nitro 更好的静态资源兼容模块
https://github.com/markthree/nitro-public-module
module nitro nitropack node public
Last synced: 29 days ago
JSON representation
nitro module for better public compatibility | 对于 nitro 更好的静态资源兼容模块
- Host: GitHub
- URL: https://github.com/markthree/nitro-public-module
- Owner: markthree
- License: mit
- Created: 2024-01-27T04:08:27.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-06T05:54:31.000Z (6 months ago)
- Last Synced: 2025-04-09T10:52:12.453Z (about 2 months ago)
- Topics: module, nitro, nitropack, node, public
- Language: TypeScript
- Homepage:
- Size: 319 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nitro-public-module
nitro module for better public compatibility
## README 🦉
[简体中文](./README_CN.md) | English
## Usage
### install
```shell
npm i nitro-public-module -D
```### Configuration Module
> nuxt
```ts
// nuxt.config.ts
import nitroPublic from "nitro-public-module";export default defineNuxtConfig({
nitro: {
modules: [nitroPublic()],
},
});
```> nitro
```ts
// nitro.config.js
import nitroPublic from "nitro-public-module";export default defineNitroConfig({
modules: [nitroPublic()],
});
```
### preset
```ts
// 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
```ts
// nitro.config.js
import nitroPublic from "nitro-public-module";export default defineNitroConfig({
modules: [
nitroPublic({
preset: false,
}),
],
});
```2. create custom middleware
```ts
// 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
};
}, {
skipDev: false, // Default to true, skip in development environment
});
```##### virtual
In addition to providing `createPublicFallbackMiddleware`, `#nitro-public` also
offers `publicDir` and `serverDir````ts
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](https://github.com/markthree)
Published under [MIT License](./LICENSE).