Coder Social home page Coder Social logo

Comments (6)

harleylang avatar harleylang commented on June 15, 2024

A temporary workaround that (1) finds all .html files in the source folder and (2) iterates over them, creating nested builds so that pages can be loaded using url directories like "www.example.com/testing/" and not "www.exmple.com/testing.html":

import esbuild from "esbuild";
import htmlPlugin from "@chialab/esbuild-plugin-html";
import findFiles from './findFiles.js'; // adapted from: https://stackoverflow.com/a/47900452/14198287

let files = findFiles('./src', '.html'); 

for (let f in files) {
  let file = files[f];
  let dir = file.split('/').slice(-2)[0];
  await esbuild.build({
    entryPoints: [file],
    outdir: `public/${dir === 'src' ? '' : dir}`,
    plugins: [htmlPlugin()],
    assetNames: "[name]",
    bundle: true,
    minify: true,
    write: true,
  }); 
};

This only works for directories 1-level deep into the src directory tree, but suits my needs for now. It's the best solution I could think of up, the main drawback being that any shared js files, assets, etc. are not shared between pages.

from rna.

CodexHere avatar CodexHere commented on June 15, 2024

Also running into this problem, which makes multi-entrypoint builds impossible with a single config as expected.

Ends up with any bundles after the first pointing to the first as their targeted js, which means they all render the same app.

According to the docs, it should work with [dir] in the *Names options: https://esbuild.github.io/api/#entry-names

from rna.

edoardocavazza avatar edoardocavazza commented on June 15, 2024

Hello @harleylang and @nerdfoundrygaming

we finally managed to release a version (0.15.17) that should handle the case. Can you help us in testing it? There may be some edge cases we missed. Thank you!

from rna.

harleylang avatar harleylang commented on June 15, 2024

Thanks @edoardocavazza !! I just tested with 0.15.17.

I can report that my nested route compiled, however I am receiving an absolute path for the assets within my root index.html file.

config:

await esbuild.build({
  entryPoints: ["src/index.html","src/study/index.html"],
  entryNames: '[dir]/[name]',
  outdir: "public",
  outbase: "src",
  plugins: [htmlPlugin()],
  assetNames: "[dir]/[name]",
  bundle: true,
  minify: true,
  write: true,
});

root index.html:
image

nested index.html:
image

from rna.

edoardocavazza avatar edoardocavazza commented on June 15, 2024

I see. Version 0.15.20 has a fix for that 🤞

from rna.

harleylang avatar harleylang commented on June 15, 2024

Closing as this is sorted on my end both locally and in production. Thank you @edoardocavazza !!

from rna.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.