hyperbrew / vite-cep-plugin

A Vite plugin to build Adobe CEP Extension Panels
MIT License
16 stars 16 forks source link

`index.html` is replaced with template contents on build #12

Closed timhaywood closed 2 years ago

timhaywood commented 2 years ago

I had some additional script tags in index.html for doing things like loading Google Analytics, fonts etc. During dev, vite uses your index.html file in /src so all works well.

On build, vite-cep-plugin replaces the html file with the template contents, removing any changes you've done to index.html yourself.

I should be able to get around this by moving things into the ts files — but I wonder if it might be possible to either:

Happy to take a look at modifying the transformIndexHtml implementation to see if I can get this working. Thanks!

timhaywood commented 2 years ago

Haven't tested it yet 😅 but something like this might work:

// transformIndexHtml() { ...
const tags: HtmlTagDescriptor[] = [
  { tag: "script", children: injectRequire },
  { tag: "script", attrs: { src: `..${jsFileName}` } },
];

if (cssFileNames) {
  tags.push(
    ...cssFileNames.map((file) => ({
      tag: "link",
      attrs: { rel: "stylesheet", href: `..${file}` },
    }))
  );
}

if (debugReact) {
  tags.push({
    tag: "script",
    attrs: { src: "http://localhost:8097" },
    injectTo: "body",
  });
}

return tags;
timhaywood commented 2 years ago

This implementation seemed to work for my repo, so created a pull request 👍 (But needs a bit more testing I think).

The default index.html in bolt-cep would also need updating, to add a few things that are missing from the template (e.g. DOCTYPE, lang attribute etc).

justintaylor-dev commented 2 years ago

Thanks for the help, should be good to go now 👍

timhaywood commented 2 years ago

So fast! Thanks Justin 🙏