简体   繁体   中英

Pass request context to webpack

I have a react + node + express + webpack client/server app.

I want to dynamically generate and serve the client front end to have dynamic meta-tags informed by the HTTP request URI.

Specifically: How does one configure webpack to accept context variables directed by HTTP request URI, and dynamically render this content?

You can't really do that with Webpack alone. Webpack is a module bundler that runs during build time to compile your code into static bundles that are later consumed by your frontend app.

It's possible to generate html using webpack with html-webpack-plugin , but I wouldn't recommend this approach for your needs.

What you can do instead is to configure your express server to dynamically generate the html. There are multiple ways of doing this. One way would be to use a templating engine with your express server to dynamically generate the markup before sending the response.

see: https://expressjs.com/en/guide/using-template-engines.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM