vite-plugin-unit 0.0.2 → 0.0.3

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/vite-plugin-unit.svg?style=for-the-badge)](https://www.npmjs.com/package/vite-plugin-unit)
4
4
 
5
- A vite plugin for handling unit.js projects
5
+ A vite plugin to enable you build websites in units using alpine.js
6
6
 
7
7
  ## installation
8
8
 
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * vite-plugin-unit
3
+ * @description A vite plugin to enable you build websites in units using alpine.js
3
4
  * @author Henry Hale
4
5
  * @license MIT
5
- * @url https://github.com/unit-js/vite-plugin-unit
6
+ * @url https://github.com/henryhale/vite-plugin-unit
6
7
  */
7
8
  import type { Plugin } from "vite";
8
9
  export type PluginOptions = {
@@ -10,4 +11,4 @@ export type PluginOptions = {
10
11
  template: string;
11
12
  slot: string;
12
13
  };
13
- export default function plugin(options: Partial<PluginOptions>): Plugin[];
14
+ export default function plugin(options?: Partial<PluginOptions>): Plugin[];
package/dist/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * vite-plugin-unit
3
+ * @description A vite plugin to enable you build websites in units using alpine.js
3
4
  * @author Henry Hale
4
5
  * @license MIT
5
- * @url https://github.com/unit-js/vite-plugin-unit
6
+ * @url https://github.com/henryhale/vite-plugin-unit
6
7
  */
7
8
  import { existsSync, readFileSync } from "node:fs";
8
9
  import { dirname, extname, join } from "node:path";
@@ -13,7 +14,7 @@ const defaultOptions = {
13
14
  template: "template.html",
14
15
  slot: "#slot#"
15
16
  };
16
- export default function plugin(options) {
17
+ export default function plugin(options = {}) {
17
18
  const opt = Object.assign({}, defaultOptions, options);
18
19
  // unit file extension
19
20
  const ext = ".unit";
@@ -86,6 +87,7 @@ export default function plugin(options) {
86
87
  res.statusCode = 200;
87
88
  res.setHeader("Content-Type", "text/html");
88
89
  const contents = await readFile(join(config.root, opt.template), { encoding: "utf-8" });
90
+ pathToCode.clear();
89
91
  const compiled = compile(file, await readFile(file, { encoding: "utf-8" }));
90
92
  res.end(contents.replace(opt.slot, compiled));
91
93
  }
@@ -98,7 +100,7 @@ export default function plugin(options) {
98
100
  filePath = filePath.replace(".html", ext);
99
101
  if (existsSync(filePath)) {
100
102
  // print request to the console
101
- log(req.method?.toUpperCase(), req.url, filePath);
103
+ log(req.method?.toUpperCase(), req.url, filePath.slice(config?.root?.length || 0));
102
104
  // send requested file
103
105
  return await respond(filePath);
104
106
  }
@@ -142,7 +144,7 @@ export default function plugin(options) {
142
144
  * Create unit.js compiled output directory
143
145
  */
144
146
  if (existsSync(output)) {
145
- rm(output, { recursive: true, force: true });
147
+ await rm(output, { recursive: true, force: true });
146
148
  }
147
149
  await mkdir(outputDir);
148
150
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-plugin-unit",
3
- "version": "0.0.2",
4
- "description": "A vite plugin for handling unit.js projects",
3
+ "version": "0.0.3",
4
+ "description": "A vite plugin to enable you build websites in units using alpine.js",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",