vite-plugin-hugo 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # vite-plugin-hugo
2
+
3
+ Integrate Hugo with Vite for modern static site development.
4
+
5
+ > [!WARNING]
6
+ > This project is experimental and not yet ready for production use.
7
+
8
+ ## Features
9
+
10
+ - **Dev Mode**: Watch and rebuild Vite assets while Hugo serves content
11
+ - **Build Mode**: Output assets to Hugo's public directory
12
+ - **Hugo as Server**: Use Hugo's development server with Vite assets
13
+ - **TypeScript Support**: Full TypeScript support out of the box
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install vite-plugin-hugo --save-dev
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ### 1. Set Up Hugo
24
+
25
+ Ensure you have a Hugo site with the following structure:
26
+
27
+ ```
28
+ my-site/
29
+ ├── content/
30
+ ├── layouts/
31
+ │ └── index.html
32
+ ├── public/
33
+ └── src/ # Your Vite assets
34
+ ├── main.ts
35
+ └── style.scss
36
+ ```
37
+
38
+ ### 2. Configure Vite
39
+
40
+ ```ts
41
+ // vite.config.ts
42
+ import { defineConfig } from "vite";
43
+ import hugo from "vite-plugin-hugo";
44
+
45
+ export default defineConfig({
46
+ plugins: [hugo()],
47
+ });
48
+ ```
49
+
50
+ ### 3. Update Hugo Layouts
51
+
52
+ Reference your Vite assets in your Hugo templates:
53
+
54
+ ```html
55
+ <!-- layouts/index.html -->
56
+ <!DOCTYPE html>
57
+ <html>
58
+ <head>
59
+ <link rel="stylesheet" href="/assets/main.css">
60
+ </head>
61
+ <body>
62
+ {{ .Content }}
63
+ <script type="module" src="/assets/main.js"></script>
64
+ </body>
65
+ </html>
66
+ ```
67
+
68
+ ## Usage
69
+
70
+ ### Development
71
+
72
+ Run Hugo server in one terminal:
73
+
74
+ ```bash
75
+ hugo server
76
+ ```
77
+
78
+ Run Vite in another terminal:
79
+
80
+ ```bash
81
+ npm run dev
82
+ ```
83
+
84
+ Vite will watch your `src/` files and rebuild to `public/assets/`. Hugo's live reload will refresh the browser.
85
+
86
+ ### Production Build
87
+
88
+ ```bash
89
+ npm run build
90
+ ```
91
+
92
+ This outputs your Vite assets to `public/assets/`, ready for deployment with Hugo.
93
+
94
+ ## Options
95
+
96
+ | Option | Type | Default | Description |
97
+ |--------|------|---------|-------------|
98
+ | `watch` | `boolean` | `true` | Watch src files and rebuild on changes |
99
+
100
+ ```ts
101
+ hugoPlugin({
102
+ watch: false // Disable file watching
103
+ })
104
+ ```
105
+
106
+ ## How It Works
107
+
108
+ - **Dev Mode**: Configures Vite to build assets to `public/assets/` with file watching enabled
109
+ - **Build Mode**: Outputs production-ready assets to `public/assets/`
110
+ - Hugo serves both your content and Vite assets from the same `public/` directory
111
+
112
+ ## Example
113
+
114
+ See the `example/` directory for a complete working example.
115
+
116
+ ## License
117
+
118
+ MIT
@@ -0,0 +1,8 @@
1
+ import { Plugin } from 'vite';
2
+ export interface HugoPluginOptions {
3
+ hugoBin?: string;
4
+ outDir?: string;
5
+ }
6
+ export declare function hugoPlugin(options?: HugoPluginOptions): Plugin;
7
+ export default hugoPlugin;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAqIlE;AAED,eAAe,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const h=require("node:child_process"),e=require("node:fs"),w=require("node:os"),t=require("node:path"),D=require("vite");function y(g={}){const{hugoBin:S,outDir:c="./static/assets"}=g;let a=!1,i;const s=t.resolve(w.tmpdir(),"vite-plugin-hugo","vite");return{name:"vite-plugin-hugo",config(o,{command:u}){return a=u==="serve",a?{logLevel:"warn",server:{fs:{allow:[".."]}},build:{outDir:s,emptyOutDir:!0,rollupOptions:{input:"./src/main.ts",output:{entryFileNames:"[name].js",assetFileNames:"[name][extname]"}}}}:{build:{outDir:c,rollupOptions:{input:"./src/main.ts",output:{entryFileNames:"[name].js",assetFileNames:"[name][extname]"}}}}},async configureServer(o){var m;i=h.spawn(S??"hugo",["server","--ignoreCache","--noHTTPCache"],{stdio:"inherit"}),(m=o.httpServer)==null||m.once("close",()=>i==null?void 0:i.kill());const u=()=>{const r=t.resolve(process.cwd(),c),p=t.resolve(s,"assets");if(e.existsSync(r)||e.mkdirSync(r,{recursive:!0}),!!e.existsSync(p))for(const d of["main.js","main.css"]){const v=t.resolve(p,d),n=t.resolve(r,d);if(!e.existsSync(v))continue;e.existsSync(n)&&e.rmSync(n,{force:!0,recursive:!0});const f=t.dirname(n);e.existsSync(f)||e.mkdirSync(f,{recursive:!0}),e.cpSync(v,n)}},l=async()=>{e.existsSync(s)&&e.rmSync(s,{force:!0,recursive:!0}),e.mkdirSync(s,{recursive:!0}),await D.build({root:process.cwd(),build:{outDir:s,emptyOutDir:!0,assetsDir:".",rollupOptions:{input:t.resolve(process.cwd(),"src/main.ts"),output:{entryFileNames:"[name].js",assetFileNames:"[name][extname]"}}}}),u()};await l(),o.watcher.on("change",async r=>{r.includes("/src/")&&await l()})}}}exports.default=y;exports.hugoPlugin=y;
package/dist/index.mjs ADDED
@@ -0,0 +1,89 @@
1
+ import { spawn as D } from "node:child_process";
2
+ import { existsSync as t, rmSync as y, mkdirSync as a, cpSync as F } from "node:fs";
3
+ import { tmpdir as N } from "node:os";
4
+ import { resolve as r, dirname as S } from "node:path";
5
+ import { build as x } from "vite";
6
+ function B(h = {}) {
7
+ const { hugoBin: w, outDir: c = "./static/assets" } = h;
8
+ let m = !1, s;
9
+ const e = r(N(), "vite-plugin-hugo", "vite");
10
+ return {
11
+ name: "vite-plugin-hugo",
12
+ // Configure Vite based on whether we're in serve or build mode
13
+ config(o, { command: u }) {
14
+ return m = u === "serve", m ? {
15
+ logLevel: "warn",
16
+ server: {
17
+ fs: { allow: [".."] }
18
+ },
19
+ build: {
20
+ outDir: e,
21
+ emptyOutDir: !0,
22
+ rollupOptions: {
23
+ input: "./src/main.ts",
24
+ output: {
25
+ entryFileNames: "[name].js",
26
+ assetFileNames: "[name][extname]"
27
+ }
28
+ }
29
+ }
30
+ } : {
31
+ build: {
32
+ outDir: c,
33
+ rollupOptions: {
34
+ input: "./src/main.ts",
35
+ output: {
36
+ entryFileNames: "[name].js",
37
+ assetFileNames: "[name][extname]"
38
+ }
39
+ }
40
+ }
41
+ };
42
+ },
43
+ // Start Hugo server when Vite dev server starts
44
+ async configureServer(o) {
45
+ var p;
46
+ s = D(
47
+ w ?? "hugo",
48
+ ["server", "--ignoreCache", "--noHTTPCache"],
49
+ {
50
+ stdio: "inherit"
51
+ }
52
+ ), (p = o.httpServer) == null || p.once("close", () => s == null ? void 0 : s.kill());
53
+ const u = () => {
54
+ const i = r(process.cwd(), c), f = r(e, "assets");
55
+ if (t(i) || a(i, { recursive: !0 }), !!t(f))
56
+ for (const v of ["main.js", "main.css"]) {
57
+ const d = r(f, v), n = r(i, v);
58
+ if (!t(d)) continue;
59
+ t(n) && y(n, { force: !0, recursive: !0 });
60
+ const g = S(n);
61
+ t(g) || a(g, { recursive: !0 }), F(d, n);
62
+ }
63
+ }, l = async () => {
64
+ t(e) && y(e, { force: !0, recursive: !0 }), a(e, { recursive: !0 }), await x({
65
+ root: process.cwd(),
66
+ build: {
67
+ outDir: e,
68
+ emptyOutDir: !0,
69
+ assetsDir: ".",
70
+ rollupOptions: {
71
+ input: r(process.cwd(), "src/main.ts"),
72
+ output: {
73
+ entryFileNames: "[name].js",
74
+ assetFileNames: "[name][extname]"
75
+ }
76
+ }
77
+ }
78
+ }), u();
79
+ };
80
+ await l(), o.watcher.on("change", async (i) => {
81
+ i.includes("/src/") && await l();
82
+ });
83
+ }
84
+ };
85
+ }
86
+ export {
87
+ B as default,
88
+ B as hugoPlugin
89
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "vite-plugin-hugo",
3
+ "version": "0.0.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "author": "Olivier Goulet",
7
+ "description": "Integrate Hugo support in Vite",
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.mjs",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.mjs",
15
+ "require": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": ["dist"],
19
+ "workspaces": ["example"],
20
+ "scripts": {
21
+ "build": "vite build",
22
+ "test": "vitest run",
23
+ "lint": "biome check .",
24
+ "format": "biome format --write ."
25
+ },
26
+ "devDependencies": {
27
+ "@biomejs/biome": "^1.9.0",
28
+ "typescript": "^5.6.0",
29
+ "vite": "^6.0.0",
30
+ "vite-plugin-dts": "^4.0.0",
31
+ "vitest": "^2.1.0"
32
+ },
33
+ "peerDependencies": {
34
+ "vite": ">=5.0.0"
35
+ }
36
+ }