We finally have all of the configuration files in place that we'll need in order to render our app on the server. We now need a file that will be invoked directly from our MVC view and will be responsible for actually rendering the application for us. Create a new ClientApp/renderOnServer.js file, then start it off with the following:
process.env.VUE_ENV = "server";
const fs = require("fs");
const path = require("path");
const filePath = path.join(__dirname, "../wwwroot/dist/main-server.js");
const code = fs.readFileSync(filePath, "utf8");
const bundleRenderer = require("vue-server-renderer").createBundleRenderer(
code
);
The important part here is how we physically read the wwwroot/dist/main-server.js file, then create a bundle renderer using the contents of it. The main-server.js file is the product of...