|
|
@@ -4,8 +4,9 @@ import os from "os";
|
|
|
import path from "path";
|
|
|
import htmlMinifier from "html-minifier-terser";
|
|
|
import esbuild from "esbuild";
|
|
|
+import forceRelativePath from "./relativePathPlugin.js";
|
|
|
|
|
|
-const parseComponent = async (file)=>{
|
|
|
+const parseComponent = async (file, prod)=>{
|
|
|
const dir = path.dirname(file);
|
|
|
let data = {};
|
|
|
if(path.extname(file) === ".neovan"){
|
|
|
@@ -13,7 +14,7 @@ const parseComponent = async (file)=>{
|
|
|
}else{
|
|
|
data = await parseHtml(file);
|
|
|
}
|
|
|
- const bundle = await createBundle(data);
|
|
|
+ const bundle = await createBundle(data, prod);
|
|
|
if(data.tmpDir) fs.rm(data.tmpDir, {recursive: true, force: true});
|
|
|
return bundle;
|
|
|
}
|
|
|
@@ -75,18 +76,22 @@ const parseHtml = async (index)=>{
|
|
|
};
|
|
|
}
|
|
|
|
|
|
-const createBundle = async (data)=>{
|
|
|
+const createBundle = async (data, prod)=>{
|
|
|
const entryPoints = [];
|
|
|
if(data.css) entryPoints.push(data.css);
|
|
|
if(data.js) entryPoints.push(data.js);
|
|
|
|
|
|
data.html = await addComponents(data.html, data.dir);
|
|
|
|
|
|
+ const plugins = [];
|
|
|
+ if(data.tmpDir) plugins.push(forceRelativePath(data.dir));
|
|
|
+
|
|
|
const esbuildProm = esbuild.build({
|
|
|
entryPoints: entryPoints,
|
|
|
bundle: true,
|
|
|
- minify: true,
|
|
|
+ minify: prod,
|
|
|
write: false,
|
|
|
+ plugins: plugins,
|
|
|
outdir: "/"
|
|
|
});
|
|
|
const htmlProm = htmlMinifier.minify(data.html, {
|