prerender-loader
prerender-loader copied to clipboard
'PRERENDER' in template.html
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>
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
}
})
thx, I'll give it a try, the 'PRERENDER' provided inside the plugin doesn't seem to be available
IIRC you can use self.PRERENDER