Skip to content
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

Add option to pass params to js files #3

Open
h-enk opened this issue Mar 28, 2023 · 0 comments
Open

Add option to pass params to js files #3

h-enk opened this issue Mar 28, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@h-enk
Copy link
Member

h-enk commented Mar 28, 2023

Update esbuild.html:

[..]
{{- /* pass hugo env to the js file as a param */ -}}
{{- /* $params := (dict "env" hugo.Environment) */ -}}

{{- $paramsDefault := (dict "env" hugo.Environment) -}}
{{- $params := "" -}}
{{- with .params -}}
{{- $params = merge $paramsDefault . -}}
{{- else -}}
{{- $params = $paramsDefault -}}
{{- end -}}
[..]

Example

In layouts\partials\footer\script-footer-core.html:

{{ $plausibleAnalyticsDomain := site.Data.starter.plausibleAnalyticsDomain -}}
{{ partial "footer/esbuild" (dict "src" "js/app.js" "targetPath" "main.js" "load" "async" "transpile" false "params" (dict "plausibleAnalyticsDomain" $plausibleAnalyticsDomain)) -}}
[..]

In assets\js\plausible.js:

[..]
import * as params from '@params';
const plausibleAnalyticsDomain = params.plausibleAnalyticsDomain;
[..]
@h-enk h-enk self-assigned this Mar 28, 2023
@h-enk h-enk added the enhancement New feature or request label Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant