2 커밋 0823d16a9b ... e7f0f7ffbc

작성자 SHA1 메시지 날짜
  Lee Morgan e7f0f7ffbc Remove code minify when in development build. 2 일 전
  Lee Morgan 7d639966e8 Add plugin for esbuild to use relative paths from neovan files. 2 일 전
3개의 변경된 파일26개의 추가작업 그리고 5개의 파일을 삭제
  1. 1 1
      index.js
  2. 9 4
      parseComponent.js
  3. 16 0
      relativePathPlugin.js

+ 1 - 1
index.js

@@ -37,7 +37,7 @@ const addRoute = async (dir, root, app, opts)=>{
     let route = dir.replace(root, "");
     route = route === "" ? "/" : route;
     if(opts.production){
-        const bundle = await parseComponent(indexFile);
+        const bundle = await parseComponent(indexFile, opts.production);
         const bundleLocation = dir.replace(opts.routesDir, ".build");
         const htmlPath = path.join(bundleLocation, "index.html");
         await fs.mkdir(bundleLocation, {recursive: true});

+ 9 - 4
parseComponent.js

@@ -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, {

+ 16 - 0
relativePathPlugin.js

@@ -0,0 +1,16 @@
+import path from "path";
+
+export default (root)=>({
+    name: "force-relative-root",
+
+    setup(build){
+        build.onResolve({filter: /^\./}, (args)=>{
+            if(!args.path.startsWith(".")) return null;
+            const resolvedPath = path.resolve(root, args.path);
+            return {
+                path: resolvedPath,
+                external: false
+            };
+        })
+    }
+});