-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal to add transformEntryToHtml
hook in plugins
#8000
Comments
related: #2321 |
ditto for https://github.com/vbenjs/vite-plugin-html, it uses ejs as well but templates MUST end with .html |
I think a simpler hook would be // vite.config.js
import {render} from 'ejs'
import {readFile, writeFile} from 'node:fs/promises'
// type createIndexHtml = {
// dependencies: string[];
// create: () => Promise<string>;
// }
const injectEjs = ({source, destination, data}) => {
name: "inject-ejs",
createIndexHtml: {
dependencies: [source],
async create() {
const template = await readFile(source, 'utf8')
const html = await render(template, data, {
async: true
})
await writeFile(destination, html)
return destination
}
}
};
export default () => {
return {
plugins: [
injectEjs({
source: 'index.html.ejs',
destination: 'index.html',
data: {
title: 'some title'
}
})
]
}
}
There is also a |
This hook (or similar) would actually solve my hacky solution in vituum. Where I'm using a workaround with renaming the files to |
Any updates on this? seems to be a common point a lot of people have arrived at |
Here is an updated vituum implementation which uses https://github.com/vituum/vituum/blob/3348010f053da61ee33c6bc5db120bd5a4b07e3b/src/utils/build.js#L31 Here is a working example of vite plugin that supports |
Clear and concise description of the problem
Think of this directory structure-
Currently, seems like there is no clear way to do the
<-- template -->
toHTML
conversion during SSG.transformIndexHtml
only runs for files with.html
extension andtransform
can only output JavaScript and not HTML.In the above example, I am guessing the implementation would look something like this-
This is exactly how I am doing things in the SSG that I am working on-
https://github.com/abelljs/abell/blob/387cf15dc81471a4f1e722fc9ad28541c64de2f5/packages/abell/src/cli/generate.ts#L53-L73
.abell
-> temporary.html
files (they don't have prod scripts and styles in them)input
so that they will take care of injecting scripts and styles and generatedist
This seems to be missing for all template engines.
For example-
.html
index.html
fileSuggested solution
A new hook called
transformEntryToHtml
.Example-
This will simplify the SSG flow a lot and will allow plugins like
vite-plugin-ejs
to have.ejs
extension.It will allow SSGs like Abell to build the output without generating temporary HTML files during the build.
Alternative
Alternative would be some way to call
transformIndexHtml
hook for files that are not HTML (don't have.html
extension).Additional context
Validations
The text was updated successfully, but these errors were encountered: