Я вижу, что стили загружены в браузере, а классы материалов находятся в загруженном CSS.
Запуск spa ng serve
Ходовой угловой Универсальный
angular.json - architect.build.options
"styles": [
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles.scss",
"node_modules/ngx-toastr/toastr.css"
],
angular.json - architect.server
"server": {
"builder": "@angular-devkit/build-angular:server",
"options": {
"outputPath": "dist/server",
"main": "src/main.server.ts",
"tsConfig": "src/tsconfig.server.json"
},
"configurations": {
"staging": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.staging.ts"
}
],
"optimization": false,
"outputHashing": "all",
"sourceMap": true,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
}
]
}
}
},
server.ts
Довольно стандартный server.ts
файл для Angular Universal.
// These are important and needed before anything else
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import { renderModuleFactory } from '@angular/platform-server';
import { enableProdMode } from '@angular/core';
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';
import * as express from 'express';
import { join } from 'path';
import { readFileSync } from 'fs';
// Faster server renders w/ Prod mode (dev mode never needed)
enableProdMode();
// Express server
const app = express();
const PORT = process.env.PORT || 4000;
const DIST_FOLDER = join(process.cwd(), 'dist');
// Our index.html we'll use as our template
const template = readFileSync(join(DIST_FOLDER, 'browser', 'index.html')).toString();
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main');
app.engine('html', (_, options, callback) => {
renderModuleFactory(AppServerModuleNgFactory, {
// Our index.html
document: template,
url: options.req.url,
// DI so that we can get lazy-loading to work differently (since we need it to just instantly render it)
extraProviders: [
provideModuleMap(LAZY_MODULE_MAP)
]
}).then(html => {
callback(null, html);
});
});
app.set('view engine', 'html');
app.set('views', join(DIST_FOLDER, 'browser'));
// Server static files from /browser
app.get('*.*', express.static(join(DIST_FOLDER, 'browser')));
app.get('/health-check', (req, res) => {
res.send(200);
});
// All regular routes use the Universal engine
app.get('*', (req, res) => {
res.render(join(DIST_FOLDER, 'browser', 'index.html'), { req });
});
// Start up the Node server
app.listen(PORT, () => {
console.log(`Node server listening on http://localhost:${PORT}`);
});
версии пакета
"@angular/cli": "~7.3.4",
"@angular/animations": "~7.2.7",
"@angular/cdk": "~7.3.7",
"@angular/common": "~7.2.7",
"@angular/compiler": "~7.2.7",
"@angular/core": "~7.2.7",
"@angular/forms": "~7.2.7",
"@angular/http": "~7.2.7",
"@angular/material": "7.3.7",
"@angular/material-moment-adapter": "^8.2.3",
"@angular/platform-browser": "~7.2.7",
"@angular/platform-browser-dynamic": "~7.2.7",
"@angular/platform-server": "^7.2.7",
"@angular/router": "~7.2.7",
"@nguniversal/common": "^7.1.1",
"@nguniversal/module-map-ngfactory-loader": "^7.1.0",