Skip to content

Commit 8a5dbf7

Browse files
Re-add server-side prerendering to Angular2 template
1 parent 444475e commit 8a5dbf7

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/Microsoft.AspNet.SpaServices/Content/Node/prerenderer.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ function loadViaWebpackNoCache(webpackConfigPath, modulePath) {
3030
webpackConfig.plugins = webpackConfig.plugins.filter(function(plugin) {
3131
return !(plugin instanceof webpack.optimize.CommonsChunkPlugin);
3232
});
33+
34+
// The typical use case for DllReferencePlugin is for referencing vendor modules. In a Node
35+
// environment, it doesn't make sense to load them from a DLL bundle, nor would that even
36+
// work, because then you'd get different module instances depending on whether a module
37+
// was referenced via a normal CommonJS 'require' or via Webpack. So just remove any
38+
// DllReferencePlugin from the config.
39+
// If someone wanted to load their own DLL modules (not an NPM module) via DllReferencePlugin,
40+
// that scenario is not supported today. We would have to add some extra option to the
41+
// asp-prerender tag helper to let you specify a list of DLL bundles that should be evaluated
42+
// in this context. But even then you'd need special DLL builds for the Node environment so that
43+
// external dependencies were fetched via CommonJS requires, so it's unclear how that could work.
44+
// The ultimate escape hatch here is just prebuilding your code as part of the application build
45+
// and *not* using asp-prerender-webpack-config at all, then you can do anything you want.
46+
webpackConfig.plugins = webpackConfig.plugins.filter(function(plugin) {
47+
return !(plugin instanceof webpack.DllReferencePlugin);
48+
});
3349

3450
// Create a compiler instance that stores its output in memory, then load its output
3551
var compiler = webpack(webpackConfig);

templates/Angular2Spa/Views/Home/Index.cshtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
ViewData["Title"] = "Home Page";
33
}
44

5-
<app>Loading...</app>
5+
<app asp-prerender-module="ClientApp/boot-server"
6+
asp-prerender-webpack-config="webpack.config.js">Loading...</app>
67

78
<script src="~/dist/vendor.js" asp-append-version="true"></script>
89
@section scripts {

0 commit comments

Comments
 (0)