vite-plugin-unit 0.0.3 → 0.0.5
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/dist/index.js +4 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @url https://github.com/henryhale/vite-plugin-unit
|
|
7
7
|
*/
|
|
8
8
|
import { existsSync, readFileSync } from "node:fs";
|
|
9
|
-
import { dirname, extname, join } from "node:path";
|
|
9
|
+
import { dirname, extname, join, resolve } from "node:path";
|
|
10
10
|
import { cp, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
11
11
|
import { log } from "node:console";
|
|
12
12
|
const defaultOptions = {
|
|
@@ -16,6 +16,8 @@ const defaultOptions = {
|
|
|
16
16
|
};
|
|
17
17
|
export default function plugin(options = {}) {
|
|
18
18
|
const opt = Object.assign({}, defaultOptions, options);
|
|
19
|
+
// https://stackoverflow.com/questions/64963450/dirname-is-not-defined
|
|
20
|
+
const __dirname = resolve(dirname(""));
|
|
19
21
|
// unit file extension
|
|
20
22
|
const ext = ".unit";
|
|
21
23
|
// source code folder
|
|
@@ -176,7 +178,7 @@ export default function plugin(options = {}) {
|
|
|
176
178
|
}
|
|
177
179
|
const fileContent = await readFile(filePath, { encoding: "utf-8" });
|
|
178
180
|
const compiledPage = compile(filePath, fileContent);
|
|
179
|
-
const result = template.replace(opt.
|
|
181
|
+
const result = template.replace(opt.slot, compiledPage);
|
|
180
182
|
log("build: ", page);
|
|
181
183
|
return await writeFile(join(outputDir, page.replace(ext, ".html")), result);
|
|
182
184
|
}
|