prerender-loader icon indicating copy to clipboard operation
prerender-loader copied to clipboard

'PRERENDER' in template.html

Open ezekielchentnik opened this issue 7 years ago • 3 comments

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>

ezekielchentnik avatar Nov 30 '18 00:11 ezekielchentnik

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 avatar Dec 03 '18 19:12 developit

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

ezekielchentnik avatar Dec 03 '18 20:12 ezekielchentnik

IIRC you can use self.PRERENDER

developit avatar Feb 22 '19 14:02 developit