Conversation
|
Isn't this a breaking change? |
|
It would break if someone happens to use |
What do you think if we also parse the remaining |
|
Additionally, SvelteKit uses %% in a different manner, but it might not matter since they have their own HTML template parsing and HTML generation. |
Yeah I think this is good to have too. I'll add a quick warning for this, and maybe we could improved later if needed. |
|
Is this feature available in 4.1.4? |
|
It's not merged yet, so no. |
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
|
hi! I know this PR was just merged like 2 days ago, but since it's in main branch, we should expect some release for this? ty! |
|
@lucassonsinlima it is already released as vite@4.2.0-beta.1. Next week 4.2 stable will go out if there aren't regressions and the current issues in ecosystem-ci are resolved |
thank you!! |
|
@bluwy @patak-dev Is there anything incorrect about trying to use it in the following way: It works well in the development environment, but when I try to run For this to work, should this transform be performed as a |
|
@bluwy @patak-dev Is there anything incorrect about trying to use it in the following way: It works well in the development environment, but when I try to run For this to work, should this transform be performed as a |
|
Thanks for the report @aardvarkk, #12404 should fix your issue. |
|
That's so cool! updated vite to use it here. |
|
Thank you, guys. 🎉 |
|
@bluwy Does this enable conditionals too, i.e. the logical equivalent of the following ejs syntax: |
|
@fritzfelix I feel that import ejs from 'ejs';
{
enforce: 'pre',
name: 'ejs-inject',
transformIndexHtml: {
order: 'pre',
handler(html) {
const template = ejs.compile(html);
process.env.REACT_APP_ENV = 'production';
return template(process.env);
}
}
} |
|
Yeah, conditionals are not planned for Vite and is documented at https://vitejs.dev/guide/env-and-mode.html#html-env-replacement. We don't want to add a potential proprietary templating style to the HTML by default. |
|
I ended up using ViteEjsPlugin, I couldn't figure out how to use this feature 🤷♂️ |
Description
Support
%ENV_NAME%syntax in HTML files. Close #3105Additional context
transformIndexHtmlas otherwise normal-hook transforms likevite-plugin-htmlmay get a parse error.%MODE%,%PROD%, etc, which are a little short, but maybe that's fine.%SSR%as I don't think it makes sense in HTML files.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).