Re-add server-side prerendering to Angular2 template

This commit is contained in:
SteveSandersonMS
2016-03-01 15:41:07 +00:00
parent 444475ef16
commit 8a5dbf7a05
2 changed files with 18 additions and 1 deletions

View File

@@ -31,6 +31,22 @@ function loadViaWebpackNoCache(webpackConfigPath, modulePath) {
return !(plugin instanceof webpack.optimize.CommonsChunkPlugin);
});
// The typical use case for DllReferencePlugin is for referencing vendor modules. In a Node
// environment, it doesn't make sense to load them from a DLL bundle, nor would that even
// work, because then you'd get different module instances depending on whether a module
// was referenced via a normal CommonJS 'require' or via Webpack. So just remove any
// DllReferencePlugin from the config.
// If someone wanted to load their own DLL modules (not an NPM module) via DllReferencePlugin,
// that scenario is not supported today. We would have to add some extra option to the
// asp-prerender tag helper to let you specify a list of DLL bundles that should be evaluated
// in this context. But even then you'd need special DLL builds for the Node environment so that
// external dependencies were fetched via CommonJS requires, so it's unclear how that could work.
// The ultimate escape hatch here is just prebuilding your code as part of the application build
// and *not* using asp-prerender-webpack-config at all, then you can do anything you want.
webpackConfig.plugins = webpackConfig.plugins.filter(function(plugin) {
return !(plugin instanceof webpack.DllReferencePlugin);
});
// Create a compiler instance that stores its output in memory, then load its output
var compiler = webpack(webpackConfig);
compiler.outputFileSystem = new MemoryFS();

View File

@@ -2,7 +2,8 @@
ViewData["Title"] = "Home Page";
}
<app>Loading...</app>
<app asp-prerender-module="ClientApp/boot-server"
asp-prerender-webpack-config="webpack.config.js">Loading...</app>
<script src="~/dist/vendor.js" asp-append-version="true"></script>
@section scripts {