-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,195 additions
and
492 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import type { Plugin } from "vite"; | ||
import type { Config } from "./types"; | ||
import { generateBoilerplate } from "./boilerplate"; | ||
import { resolve } from "./utils/resolve"; | ||
import { createServer } from "./server/create"; | ||
import { hotupdate } from "./server/hot"; | ||
import { getLayout } from "./utils/layouts"; | ||
import { getInputs } from "./utils/input"; | ||
import glob from "tiny-glob"; | ||
import copy from "rollup-plugin-copy"; | ||
|
||
export const multipage = (config?: Config): Plugin => { | ||
const root = config?.directory || "src/pages"; | ||
const assets = config?.assets || []; | ||
let framework = config?.framework || ""; | ||
|
||
return { | ||
name: "vite-plugin-multip", | ||
async config() { | ||
const pages = await glob("**/*.{svelte,vue,tsx,jsx}", { | ||
cwd: root, | ||
filesOnly: true, | ||
}); | ||
|
||
const [input, recognizedFramework] = getInputs(pages, root); | ||
|
||
if (!input) throw new Error("No input found"); | ||
if (!framework) framework = recognizedFramework; | ||
|
||
return { | ||
root, | ||
build: { | ||
outDir: "dist", | ||
emptyOutDir: true, | ||
rollupOptions: { | ||
input, | ||
output: { | ||
dir: "dist", | ||
}, | ||
plugins: [ | ||
copy({ | ||
targets: [{ src: "public/*", dest: "dist/" }, ...assets], | ||
}), | ||
], | ||
}, | ||
}, | ||
}; | ||
}, | ||
|
||
resolveId(id) { | ||
return id.includes("index.html") ? id : null; | ||
}, | ||
|
||
async load(id) { | ||
if (framework === "") throw new Error("Framework not found"); | ||
|
||
const fileName = "index.html"; | ||
|
||
if (!id.endsWith(fileName)) return null; | ||
|
||
id = resolve(id); | ||
|
||
const page = id.replace(fileName, `index.${framework}`); | ||
const layout = await getLayout(page); | ||
|
||
return await generateBoilerplate(page, framework, config || {}, layout); | ||
}, | ||
|
||
configureServer: createServer, | ||
handleHotUpdate: hotupdate, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# vite-plugin-multip docs | ||
|
||
Documentation of the plugin (web version in arrtive) vite-plugin-multip | ||
|
||
- [layouts](https://github.com/vclemenzi/vite-plugin-multip/blob/main/docs/layouts.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.