Skip to content

Commit

Permalink
refactor: format
Browse files Browse the repository at this point in the history
  • Loading branch information
vclemenzi committed Mar 22, 2024
1 parent 5fe4acc commit c749fae
Show file tree
Hide file tree
Showing 16 changed files with 1,195 additions and 492 deletions.
34 changes: 17 additions & 17 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "20"

- name: Install Dependencies
run: npm install
- name: Install Dependencies
run: npm install

- name: Build Examples
run: |
cd examples
for folder in */; do
cd $folder
npm install
npm run build
cd ..
done
- name: Build Examples
run: |
cd examples
for folder in */; do
cd $folder
npm install
npm run build
cd ..
done
72 changes: 72 additions & 0 deletions :w
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,
};
};
1 change: 1 addition & 0 deletions docs/README.md
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)
22 changes: 11 additions & 11 deletions docs/layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ When utilizing the `vite-plugin-multip` plugin, you gain the capability to finel
Below is a minimalist illustration of a custom layout file, `layout.html`, showcasing the fundamental structure:

```html
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Custom Layout</title>
</head>
<body>
</head>
<body>
<header>
<h1>Header</h1>
<h1>Header</h1>
</header>

<main>
<!-- Page content will be inserted here -->
<slot />
<!-- Page content will be inserted here -->
<slot />
</main>

<footer>
<p>Footer</p>
<p>Footer</p>
</footer>
</body>
</body>
</html>
```

Expand Down
Loading

0 comments on commit c749fae

Please sign in to comment.