woveer-vite-plugin
v0.3.12
Published
Woover Vite Plugin For Dynamic Routing
Readme
Woveer Vite Plugin
The Woveer Vite Plugin provides configurations for JavaScript and TypeScript, supporting exporting patterns to create routes for client or server.
Usage
javascript
npx woveer-create-app myapptypescript
npx woveer-create-app myapp --typescriptInstall and Run
cd myapp && npm install && npm run devClient Entry Point
src/client.js
import { ClientConfig } from 'woveer-vite-plugin/client'
import { Root, Loading, Error, Layout } from '@components'
export const config = ClientConfig(() => {
return { Root, Loading, Error, Layout }
})Server Entry Point
src/server.js
import { ServerConfig } from 'woveer-vite-plugin/server'
import { RunEachMinute, AuthMiddleware } from '@services'
export const config = ServerConfig(() => {
return {
scheduler: { '* * * * *': RunEachMinute },
middlewares: [ AuthMiddleware ]
}
})Creating Routes in Client
src/product/index.jsx
export const View = () => {
return <>Hello World!</>
}
// route http://localhost:5173/productCreating Routes in Server
src/product/[id].js
export const Rest = async (req) => {
return { message: 'Hello World!' }
}
// route http://localhost:5173/api/product/1Environment variables
.env
CLIENT_PARAM=4321
SERVER_PARAM=1234Must have prefix CLIENT_ OR SERVER_
Client
import.meta.env.CLIENT_PARAMServer
import.meta.env.SERVER_PARAMConfiguration
vite.config.js
import { defineConfig } from 'vite';
import WoveerVitePlugin from 'woveer-vite-plugin';
export default defineConfig({
plugins: [
WoveerVitePlugin({
appname: 'My App',
client: {
entry: 'src/client.js',
metadata: [{
name: "viewport",
content: "width=device-width, initial-scale=1.0"
}],
links: [{
href: "https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap",
rel: "stylesheet"
}]
},
server: {
entry: 'src/server.js',
prefix: '/api',
origin: '*',
limit: '1mb'
},
prod: {
port: 80,
crt: 'myapp.crt',
key: 'private.key'
}
})
]
})