🚀 We're pleased to announce the release of ReactJS.NET 5.2. In this release:
Templates
This update contains a brand new feature - templates! This feature makes it much easier to get started on a new project.
To start a new ASP.NET Core project using React and server-side rendering:
dotnet new -i React.Template
dotnet new reactnet-webpack
dotnet run
The reactnet-vanilla
template is also available for projects that don't need webpack.
Webpack Asset Manifest Support
If you've ever wanted to use hashes in the filenames of generated assets, this feature is for you! When using Webpack and webpack-manifest-plugin
, it's now possible to render the script and style tags automatically from the generated asset manifest. This can be especially helpful when using caching headers to instruct the client not to refetch these static assets from the server.
If using the filename pattern '[name].[contenthash:8].js'
, webpack will emit files that look like this:
vendor.8faee7f5.js
main-0c14766b.js
Configure reading these files server-side with config.SetReactAppBuildPath("~/dist");
where dist
is the directory where webpack emits the built assets.
In your view code, call:
@Html.ReactGetStylePaths() // in the doucment head next to other stylesheets
@Html.ReactGetScriptPaths() // right before the body closing tag
Next, define an asset manifest format in your webpack config. Check out the sample webpack config for the format the asset manifest is expected to follow.
At render time, the asset manifest will be read from the dist
directory and be mapped into script
and style
tags for the browser to download.
The reactnet-webpack
sample uses this layout, so give it a try if you're curious!
Thanks
If this library has made a difference to you in either a work or personal project, I'd love to hear from you. We don't get paid at all to work on this, it's just for fun! Drop a line @dustinsoftware or @Daniel15
Cheers,
Dustin