jingrow-ui/vite/jinjaBootData.js
jingrow c7bac1a7a0
Some checks failed
Publish on NPM / publish (push) Has been cancelled
Build and Deploy Storybook / build (push) Has been cancelled
Tests / test (push) Has been cancelled
initial commit
2025-10-24 00:40:30 +08:00

24 lines
561 B
JavaScript

export function jinjaBootData() {
return {
name: 'jingrowui-jinja-boot-data-plugin',
transformIndexHtml(html, context) {
if (!context.server) {
// context.server is true in dev mode
// only inject this in production build
return html.replace(
/<\/body>/,
`
<script>
{% for key in boot %}
window["{{ key }}"] = {{ boot[key] | tojson }};
{% endfor %}
</script>
</body>
`,
)
}
return html
},
}
}