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

'PRERENDER' in template.html #24

Open
ezekielchentnik opened this issue Nov 30, 2018 · 3 comments
Open

'PRERENDER' in template.html #24

ezekielchentnik opened this issue Nov 30, 2018 · 3 comments
Labels
question Further information is requested

Comments

@ezekielchentnik
Copy link

is there a way to access 'PRERENDER' env variable inside a regular template.html?

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <script>
        if ('serviceWorker' in navigator) {
            navigator.serviceWorker.register('/service-worker.js');
        }
    </script>
    <title>Taco</title>
    <meta name="mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <link rel="manifest" href="/manifest.json" />
</head>

<body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="portal"></div>
    <main id="root">{{prerender:./prerender.js}}</div>
</body>

</html>

@developit
Copy link
Collaborator

developit commented Dec 3, 2018

Hmm - I think it should be there? That gets into one of the weirder issues with DefinePlugin - it leaks into parent compiler instances, but perhaps it doesn't leak into sibling compilers? If so then there's no way to have that variable exposed to your template.

One option would be to pass a value directly to html-webpack-plugin via the templateParameters option:

new HtmlWebpackPlugin({
  template: '!!prerender-loader!template.html',
  templateParameters: {
    PRERENDER: true
  }
})

@developit developit added the question Further information is requested label Dec 3, 2018
@ezekielchentnik
Copy link
Author

thx, I'll give it a try, the 'PRERENDER' provided inside the plugin doesn't seem to be available

@developit
Copy link
Collaborator

IIRC you can use self.PRERENDER

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants